public ClientWebSocketChannel Option <T>(ChannelOption <T> option, T value)
        {
            Contract.Requires(option != null);

            Configuration.SetOption(option, value);
            return(this);
        }
Esempio n. 2
0
 public bool SetOption(ChannelOption option, int value)
 {
     if (option != ChannelOption.MaxPendingBuffers)
     {
         return(false);
     }
     if (!this.m_IsReliable)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Cannot set MaxPendingBuffers on unreliable channel " + this.m_ChannelId);
         }
         return(false);
     }
     if ((value < 0) || (value >= 0x200))
     {
         if (LogFilter.logError)
         {
             Debug.LogError(string.Concat(new object[] { "Invalid MaxPendingBuffers for channel ", this.m_ChannelId, ". Must be greater than zero and less than ", 0x200 }));
         }
         return(false);
     }
     this.m_MaxPendingPacketCount = value;
     return(true);
 }
Esempio n. 3
0
        public override bool SetOption <T>(ChannelOption <T> option, T value)
        {
            Validate(option, value);

            if (ChannelOption.SoRcvbuf.Equals(option))
            {
                ReceiveBufferSize = (int)(object)value;
            }
            else if (ChannelOption.SoReuseaddr.Equals(option))
            {
                ReuseAddress = (bool)(object)value;
            }
            else if (ChannelOption.SoBacklog.Equals(option))
            {
                Backlog = (int)(object)value;
            }
            else if (ChannelOption.SoLinger.Equals(option))
            {
                Linger = (int)(object)value;
            }
            else
            {
                return(base.SetOption(option, value));
            }

            return(true);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            CopierImplementation implementation;

            if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
            {
                CopierImplementationMode mode = Enum.Parse <CopierImplementationMode>(args[0]);
                implementation = new CopierImplementation(mode);
            }
            else
            {
                implementation = new CopierImplementation();
            }

            ChannelOption[] options = new ChannelOption[] {  };
            Server          server  = new Server(options)
            {
                Services = { Copier.BindService(implementation) },
                Ports    = { new ServerPort("localhost", CopyConstants.PortNumber, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Listening");
            Console.ReadLine();
        }
Esempio n. 5
0
        /// <inheritdoc/>
        public CallInvoker GetFor(Type type, string host = default, int port = default)
        {
            ThrowIfTypeDoesNotImplementClientBase(type);

            var client = _knownClients.GetFor(type);
            var endpointConfiguration = _configuration[client.Visibility];

            var keepAliveTime         = new ChannelOption("grpc.keepalive_time", 1000);
            var keepAliveTimeout      = new ChannelOption("grpc.keepalive_timeout_ms", 500);
            var keepAliveWithoutCalls = new ChannelOption("grpc.keepalive_permit_without_calls", 1);

            host = host == default ? endpointConfiguration.Host : host;
            port = port == default ? endpointConfiguration.Port : port;
            var channel = new Channel(
                host,
                port,
                ChannelCredentials.Insecure,
                new[] { keepAliveTime, keepAliveTimeout, keepAliveWithoutCalls });

            return(channel.Intercept(_ =>
            {
                _metadataProviders.Provide().ForEach(_.Add);
                return _;
            }));
        }
        public override T GetOption <T>(ChannelOption <T> option)
        {
            if (ChannelOption.SoRcvbuf.Equals(option))
            {
                return((T)(object)ReceiveBufferSize);
            }
            if (ChannelOption.SoSndbuf.Equals(option))
            {
                return((T)(object)SendBufferSize);
            }
            if (ChannelOption.TcpNodelay.Equals(option))
            {
                return((T)(object)TcpNoDelay);
            }
            if (ChannelOption.SoKeepalive.Equals(option))
            {
                return((T)(object)KeepAlive);
            }
            if (ChannelOption.SoReuseaddr.Equals(option))
            {
                return((T)(object)ReuseAddress);
            }
            if (ChannelOption.SoLinger.Equals(option))
            {
                return((T)(object)Linger);
            }
            if (ChannelOption.AllowHalfClosure.Equals(option))
            {
                return((T)(object)AllowHalfClosure);
            }

            return(base.GetOption(option));
        }
Esempio n. 7
0
        public ServerWebSocketChannel Option <T>(ChannelOption <T> option, T value)
        {
            Preconditions.CheckNotNull(option);

            this.Configuration.SetOption(option, value);
            return(this);
        }
        /// <summary>
        /// Creates the specific communication client based on grpc technoligy
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="chunkSender">The chunkSender<see cref="IChunkSender{Command, FetchRequest, GrpcResponse}"/></param>
        /// <param name="chunkReceiver">The chunkReceiver<see cref="IChunkReceiver{Command}"/></param>
        /// <returns>The <see cref="IClient{Command, FetchRequest, GrpcResponse}"/></returns>
        public static IClient <Command, FetchRequest, GrpcResponse> Create(string address, IChunkSender <Command, FetchRequest, GrpcResponse> chunkSender, IChunkReceiver <Command> chunkReceiver)
        {
            try
            {
                var           endPoint      = address.ToIpEndpoint();
                Channel       channel       = null;
                ChannelOption optionReceive = new ChannelOption(ChannelOptions.MaxReceiveMessageLength, GrpcStream.MaxPackageSize);
                ChannelOption optionSend    = new ChannelOption(ChannelOptions.MaxSendMessageLength, GrpcStream.MaxPackageSize);

                if (System.IO.File.Exists("ca.crt"))
                {
                    var cacert     = System.IO.File.ReadAllText(@"ca.crt");
                    var clientcert = System.IO.File.ReadAllText(@"client.crt");
                    var clientkey  = System.IO.File.ReadAllText(@"client.key");
                    var ssl        = new SslCredentials(cacert, new KeyCertificatePair(clientcert, clientkey));
                    channel = new Channel(string.Format("{0}:{1}", endPoint.Address.ToString(), endPoint.Port), ssl);
                }
                else
                {
                    channel = new Channel(string.Format("{0}:{1}", endPoint.Address.ToString(), endPoint.Port), ChannelCredentials.Insecure, new List <ChannelOption>()
                    {
                        optionReceive, optionSend
                    });
                }

                return(new GrpcClient(channel, endPoint, chunkSender, chunkReceiver));
            }
            catch (Exception ex)
            {
                throw new Exception("Grpc initialization error", ex);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Head"/> class.
        /// </summary>
        /// <param name="headId"><see cref="HeadId"/> of the client.</param>
        /// <param name="host">Hostname of the client.</param>
        /// <param name="port">TCP port to connect back to the client.</param>
        /// <param name="runtime">Runtime information from the client.</param>
        /// <param name="servicesByName">Names of services exposed.</param>
        /// <param name="connectionTime">Time of when client was connected.</param>
        public Head(
            HeadId headId,
            string host,
            int port,
            string runtime,
            IEnumerable <string> servicesByName,
            DateTimeOffset connectionTime)
        {
            HeadId         = headId;
            Host           = host;
            Port           = port;
            Runtime        = runtime;
            ServicesByName = servicesByName;
            ConnectionTime = connectionTime;

            var keepAliveTime         = new ChannelOption("grpc.keepalive_time", 1000);
            var keepAliveTimeout      = new ChannelOption("grpc.keepalive_timeout_ms", 500);
            var keepAliveWithoutCalls = new ChannelOption("grpc.keepalive_permit_without_calls", 1);

            Channel = new Channel(
                host,
                (int)port,
                ChannelCredentials.Insecure,
                new[] { keepAliveTime, keepAliveTimeout, keepAliveWithoutCalls });
        }
Esempio n. 10
0
        public void NoChannelPoolConfig()
        {
            var config  = new ApiConfig();
            var options = new ChannelOption[] { new ChannelOption(GcpCallInvoker.ApiConfigChannelArg, config.ToString()) };

            Assert.ThrowsException <ArgumentException>(() => new GcpCallInvoker("localhost", 12345, ChannelCredentials.Insecure, options));
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            const int Port = 50052;
            const int MaxMessageLengthBytes = Int32.MaxValue;

            var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);

            ChannelOption maxReceiveMessageLength = new ChannelOption(ChannelOptions.MaxMessageLength, MaxMessageLengthBytes);

            //ChannelOption maxSendMessageLength = new ChannelOption(ChannelOptions.MaxMessageLength, MaxMessageLengthBytes);
            ChannelOption[] grpcChannelOptions = { maxReceiveMessageLength };

            Server server = new Server(grpcChannelOptions)
                            //Server server = new Server()
            {
                Services = { RouteGuide.BindService(new RouteGuideImpl(features)) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("RouteGuide server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
Esempio n. 12
0
        public override bool SetOption <T>(ChannelOption <T> option, T value)
        {
            if (base.SetOption(option, value))
            {
                return(true);
            }

            if (ChannelOption.SoRcvbuf.Equals(option))
            {
                this.SetReceiveBufferSize((int)(object)value);
            }
            else if (ChannelOption.SoSndbuf.Equals(option))
            {
                this.SetSendBufferSize((int)(object)value);
            }
            else if (ChannelOption.TcpNodelay.Equals(option))
            {
                this.SetTcpNoDelay((bool)(object)value);
            }
            else if (ChannelOption.SoKeepalive.Equals(option))
            {
                this.SetKeepAlive((bool)(object)value);
            }
            else if (ChannelOption.SoReuseaddr.Equals(option))
            {
                this.SetReuseAddress((bool)(object)value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Esempio n. 13
0
        /// <summary>
        /// To build a gRpc service config includes retry policy for given gRpcServices
        /// The service config will look like this
        ///      "{\n"
        ///      "  \"methodConfig\": [ {\n"
        ///      "    \"name\": [\n"
        ///      "      { \"service\": \"service\", \"method\": \"method\" }\n"
        ///      "    ],\n"
        ///      "    \"retryPolicy\": {\n"
        ///      "      \"maxAttempts\": 2,\n"
        ///      "      \"initialBackoff\": \"1s\",\n"
        ///      "      \"maxBackoff\": \"120s\",\n"
        ///      "      \"backoffMultiplier\": 1.6,\n"
        ///      "      \"retryableStatusCodes\": [ \"ABORTED\" ]\n"
        ///      "    }\n"
        ///      "  } ]\n"
        ///      "}");
        /// </summary>
        /// <param name="gRpcServices"></param>
        /// <param name="retryPolicy"></param>
        /// <returns></returns>
        private ChannelOption[] BuildChannelOptions(IGrpcService[] gRpcServices, RetryPolicy retryPolicy)
        {
            if (retryPolicy == null)
            {
                return(Array.Empty <ChannelOption>());
            }
            else
            {
                string        retryPolicyString = retryPolicy.BuildPolicyString();
                List <string> gRpcServicesNames = new List <string>();
                foreach (var gRpcService in gRpcServices)
                {
                    foreach (var methodName in gRpcService.MethodsName)
                    {
                        gRpcServicesNames.Add($"{{\"service\":\"{gRpcService.ServiceName}\", \"method\":\"{methodName}\"}}");
                    }
                }

                string        serviceNames      = string.Join(",", gRpcServicesNames);
                string        serviceNameString = $"\"name\":[{serviceNames}]";
                string        serviceConfig     = $"{{\"methodConfig\":[{{{serviceNameString},{retryPolicyString}}}]}}";
                ChannelOption channelOption     = new ChannelOption(GRPC_ARG_SERVICE_CONFIG, serviceConfig);

                return(new ChannelOption[] { channelOption });
            }
        }
Esempio n. 14
0
        public override bool SetOption <T>(ChannelOption <T> option, T value)
        {
            this.Validate(option, value);

            if (ChannelOption.SoRcvbuf.Equals(option))
            {
                this.SetReceiveBufferSize((int)(object)value);
            }
            else if (ChannelOption.SoReuseaddr.Equals(option))
            {
                this.SetReuseAddress((bool)(object)value);
            }
            else if (ChannelOption.SoReuseport.Equals(option))
            {
                this.SetReusePort((bool)(object)value);
            }
            else if (ChannelOption.SoBacklog.Equals(option))
            {
                this.backlog = (int)(object)value;
            }
            else
            {
                return(base.SetOption(option, value));
            }

            return(true);
        }
Esempio n. 15
0
        public override T GetOption <T>(ChannelOption <T> option)
        {
            if (ChannelOption.SoRcvbuf.Equals(option))
            {
                return((T)(object)this.GetReceiveBufferSize());
            }
            if (ChannelOption.SoSndbuf.Equals(option))
            {
                return((T)(object)this.GetSendBufferSize());
            }
            if (ChannelOption.TcpNodelay.Equals(option))
            {
                return((T)(object)this.GetTcpNoDelay());
            }
            if (ChannelOption.SoKeepalive.Equals(option))
            {
                return((T)(object)this.GetKeepAlive());
            }
            if (ChannelOption.SoReuseaddr.Equals(option))
            {
                return((T)(object)this.GetReuseAddress());
            }

            return(base.GetOption(option));
        }
Esempio n. 16
0
 public bool SetOption(ChannelOption option, int value)
 {
     if (option == ChannelOption.MaxPendingBuffers)
     {
         if (!m_IsReliable)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Cannot set MaxPendingBuffers on unreliable channel " + m_ChannelId);
             }
             return(false);
         }
         if (value < 0 || value >= 512)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Invalid MaxPendingBuffers for channel " + m_ChannelId + ". Must be greater than zero and less than " + 512);
             }
             return(false);
         }
         m_MaxPendingPacketCount = value;
         return(true);
     }
     return(false);
 }
Esempio n. 17
0
 void PopulateChannelMenuOptions()
 {
     nameSubMenu          = new AlwaysDisabledOption(Name);
     lineColorSubMenu     = new GroupHeadOption("Color");
     lineThicknessSubMenu = new GroupHeadOption("Thickness");
     lineOpacitySubMenu   = new GroupHeadOption("Opacity");
     ChannelOptions.SoftwareOptions.SubOptions.Add(nameSubMenu);
     ChannelOptions.SoftwareOptions.SubOptions.Add(lineColorSubMenu);
     ChannelOptions.SoftwareOptions.SubOptions.Add(lineThicknessSubMenu);
     ChannelOptions.SoftwareOptions.SubOptions.Add(lineOpacitySubMenu);
     ChannelOptions.SoftwareOptions.Enabled = true;
     for (int i = 1; i <= 8; i++)
     {
         var op = new LineThicknessOption(i);
         op.Checked = i == LineThickness;
         lineThicknessSubMenu.SubOptions.Add(op);
         op.MenuItem.Click += LineThicknessItemClick;
     }
     foreach (var col in GraphicsUtils.CommonColors())
     {
         var op = new LineColorOption(col);
         op.Checked = col.R == LineColor.R && col.G == LineColor.G && col.B == LineColor.B;
         lineColorSubMenu.SubOptions.Add(op);
         op.MenuItem.Click += LineColorItemClick;
     }
     for (int i = 10; i <= 100; i += 10)
     {
         var op = new LineOpacityOption(i / 100.0F);
         int t  = (int)Math.Round(LineOpacity * 100);
         op.Checked = i == t;
         lineOpacitySubMenu.SubOptions.Add(op);
         op.MenuItem.Click += LineOpacityItemClick;
     }
 }
Esempio n. 18
0
        internal ZeebeClient(string address,
                             ChannelCredentials credentials,
                             TimeSpan?keepAlive,
                             Func <int, TimeSpan> sleepDurationProvider,
                             ILoggerFactory loggerFactory = null)
        {
            this.loggerFactory = loggerFactory;

            var channelOptions  = new List <ChannelOption>();
            var userAgentString = "client: csharp, version: " + typeof(ZeebeClient).Assembly.GetName().Version;
            var userAgentOption = new ChannelOption(ChannelOptions.PrimaryUserAgentString, userAgentString);

            channelOptions.Add(userAgentOption);

            AddKeepAliveToChannelOptions(channelOptions, keepAlive);

            channelToGateway =
                new Channel(address, credentials, channelOptions);
            gatewayClient = new Gateway.GatewayClient(channelToGateway);


            asyncRetryStrategy =
                new TransientGrpcErrorRetryStrategy(sleepDurationProvider ??
                                                    DefaultWaitTimeProvider);
        }
Esempio n. 19
0
 /// <summary>
 ///   <para>This sets an option on the network channel.</para>
 /// </summary>
 /// <param name="channelId">The channel the option will be set on.</param>
 /// <param name="option">The option to set.</param>
 /// <param name="value">The value for the option.</param>
 /// <returns>
 ///   <para>True if the option was set.</para>
 /// </returns>
 public bool SetChannelOption(int channelId, ChannelOption option, int value)
 {
     if (this.m_Channels == null || channelId < 0 || channelId >= this.m_Channels.Length)
     {
         return(false);
     }
     return(this.m_Channels[channelId].SetOption(option, value));
 }
Esempio n. 20
0
 public bool SetOption(ChannelOption option, object value)
 {
     if (option == null)
     {
         throw new ArgumentNullException(nameof(option), "The Channel Option cannot be null.");
     }
     return(option.Set(this, value));
 }
Esempio n. 21
0
 public bool SetChannelOption(int channelId, ChannelOption option, int value)
 {
     if (this.m_Channels == null)
     {
         return(false);
     }
     return(((channelId >= 0) && (channelId < this.m_Channels.Length)) && this.m_Channels[channelId].SetOption(option, value));
 }
Esempio n. 22
0
        public bool SetOption(ChannelOption option, int value)
        {
            bool result;

            if (option != ChannelOption.MaxPendingBuffers)
            {
                if (option != ChannelOption.AllowFragmentation)
                {
                    if (option != ChannelOption.MaxPacketSize)
                    {
                        result = false;
                    }
                    else if (!_currentPacket.IsEmpty() || _pendingPackets.Count > 0)
                    {
                        Debug.LogError("Cannot set MaxPacketSize after sending data.");
                        result = false;
                    }
                    else if (value <= 0)
                    {
                        Debug.LogError("Cannot set MaxPacketSize less than one.");
                        result = false;
                    }
                    else if (value > _maxPacketSize)
                    {
                        Debug.LogError(
                            $"Cannot set MaxPacketSize to greater than the existing maximum ({_maxPacketSize}).");
                        result = false;
                    }
                    else
                    {
                        _currentPacket = new QChannelPacket(value, _isReliable);
                        _maxPacketSize = value;
                        result         = true;
                    }
                }
                else
                {
                    _allowFragmentation = value != 0;
                    result = true;
                }
            }
            else if (!_isReliable)
            {
                result = false;
            }
            else if (value < 0 || value >= 512)
            {
                Debug.LogError(
                    $"Invalid MaxPendingBuffers for channel {_channelId}. Must be greater than zero and less than {512}");
                result = false;
            }
            else
            {
                _maxPendingPacketCount = value;
                result = true;
            }
            return(result);
        }
Esempio n. 23
0
        public bool SetOption(ChannelOption option, int value)
        {
            switch (option)
            {
            case ChannelOption.MaxPendingBuffers:
                if (!m_IsReliable)
                {
                    return(false);
                }
                if (value < 0 || value >= 512)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Invalid MaxPendingBuffers for channel " + m_ChannelId + ". Must be greater than zero and less than " + 512);
                    }
                    return(false);
                }
                m_MaxPendingPacketCount = value;
                return(true);

            case ChannelOption.AllowFragmentation:
                m_AllowFragmentation = (value != 0);
                return(true);

            case ChannelOption.MaxPacketSize:
                if (!m_CurrentPacket.IsEmpty() || m_PendingPackets.Count > 0)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Cannot set MaxPacketSize after sending data.");
                    }
                    return(false);
                }
                if (value <= 0)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Cannot set MaxPacketSize less than one.");
                    }
                    return(false);
                }
                if (value > m_MaxPacketSize)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Cannot set MaxPacketSize to greater than the existing maximum (" + m_MaxPacketSize + ").");
                    }
                    return(false);
                }
                m_CurrentPacket = new ChannelPacket(value, m_IsReliable);
                m_MaxPacketSize = value;
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 24
0
        public void StringOption()
        {
            var option = new ChannelOption("somename", "ABCDEF");

            Assert.AreEqual(ChannelOption.OptionType.String, option.Type);
            Assert.AreEqual("somename", option.Name);
            Assert.AreEqual("ABCDEF", option.StringValue);
            Assert.Throws(typeof(InvalidOperationException), () => { var s = option.IntValue; });
        }
Esempio n. 25
0
        public void Initialize()
        {
            ChannelOption option = new ChannelOption(_minimalFilter);

            foreach (var s in _receiver.Handlers)
            {
                s.CollectChannelOption(option);
            }
            _minimalFilter = option.CurrentMinimalFilter;
        }
Esempio n. 26
0
        public void Constructor_RejectsDuplicateOptions()
        {
            var options = new ChannelOption[]
            {
                new ChannelOption(ChannelOptions.PrimaryUserAgentString, "ABC"),
                new ChannelOption(ChannelOptions.PrimaryUserAgentString, "XYZ")
            };

            Assert.Throws(typeof(ArgumentException), () => new Channel("127.0.0.1", ChannelCredentials.Insecure, options));
        }
Esempio n. 27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="host"></param>
 /// <param name="port"></param>
 /// <param name="options"></param>
 public RClient(string host, int port, IEnumerable <ChannelOption> options = null)
 {
     if (options is null)
     {
         options = new ChannelOption[] { }
     }
     ;
     channel = new Channel(host, port, ChannelCredentials.Insecure, options);
     client  = new DeployService.DeployServiceClient(channel);
 }
Esempio n. 28
0
        public GrpcServer(FunctionRpc.FunctionRpcBase serviceImpl)
        {
            ChannelOption maxReceiveMessageLength = new ChannelOption(ChannelOptions.MaxReceiveMessageLength, MaxMessageLengthBytes);
            ChannelOption maxSendMessageLength    = new ChannelOption(ChannelOptions.MaxSendMessageLength, MaxMessageLengthBytes);

            ChannelOption[] grpcChannelOptions = { maxReceiveMessageLength, maxSendMessageLength };
            _server = new Server(grpcChannelOptions)
            {
                Services = { FunctionRpc.BindService(serviceImpl) },
                Ports    = { new ServerPort("127.0.0.1", ServerPort.PickUnused, ServerCredentials.Insecure) }
            };
        }
Esempio n. 29
0
        public override bool SetOption <T>(ChannelOption <T> option, T value)
        {
            if (base.SetOption(option, value))
            {
                return(true);
            }

            if (ChannelOption.SoBroadcast.Equals(option))
            {
                this.Broadcast = (bool)(object)value;
            }
            else if (ChannelOption.SoRcvbuf.Equals(option))
            {
                this.ReceiveBufferSize = (int)(object)value;
            }
            else if (ChannelOption.SoSndbuf.Equals(option))
            {
                this.SendBufferSize = (int)(object)value;
            }
            else if (ChannelOption.SoReuseaddr.Equals(option))
            {
                this.ReuseAddress = (bool)(object)value;
            }
            else if (ChannelOption.IpMulticastLoopDisabled.Equals(option))
            {
                this.LoopbackModeDisabled = (bool)(object)value;
            }
            else if (ChannelOption.IpMulticastTtl.Equals(option))
            {
                this.TimeToLive = (short)(object)value;
            }
            else if (ChannelOption.IpMulticastAddr.Equals(option))
            {
                this.Interface = (EndPoint)(object)value;
            }
            else if (ChannelOption.IpMulticastIf.Equals(option))
            {
                this.NetworkInterface = (NetworkInterface)(object)value;
            }
            else if (ChannelOption.IpTos.Equals(option))
            {
                this.TrafficClass = (int)(object)value;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Esempio n. 30
0
 /// <summary>
 /// Allow to specify a {@link ChannelOption} which is used for the {@link Channel} instances once they got
 /// created. Use a value of {@code null} to remove a previous set {@link ChannelOption}.
 /// </summary>
 public TBootstrap Option <T>(ChannelOption <T> option, T value)
 {
     Contract.Requires(option != null);
     if (value == null)
     {
         object removed;
         this.options.TryRemove(option, out removed);
     }
     else
     {
         this.options[option] = value;
     }
     return((TBootstrap)this);
 }
 public bool SetOption(ChannelOption option, int value)
 {
   if (option != ChannelOption.MaxPendingBuffers)
     return false;
   if (!this.m_IsReliable)
   {
     if (LogFilter.logError)
       Debug.LogError((object) ("Cannot set MaxPendingBuffers on unreliable channel " + (object) this.m_ChannelId));
     return false;
   }
   if (value < 0 || value >= 512)
   {
     if (LogFilter.logError)
       Debug.LogError((object) ("Invalid MaxPendingBuffers for channel " + (object) this.m_ChannelId + ". Must be greater than zero and less than " + (object) 512));
     return false;
   }
   this.m_MaxPendingPacketCount = value;
   return true;
 }
 /// <summary>
 ///   <para>This sets an option on the network channel.</para>
 /// </summary>
 /// <param name="channelId">The channel the option will be set on.</param>
 /// <param name="option">The option to set.</param>
 /// <param name="value">The value for the option.</param>
 /// <returns>
 ///   <para>True if the option was set.</para>
 /// </returns>
 public bool SetChannelOption(int channelId, ChannelOption option, int value)
 {
   if (this.m_Channels == null || channelId < 0 || channelId >= this.m_Channels.Length)
     return false;
   return this.m_Channels[channelId].SetOption(option, value);
 }
Esempio n. 33
0
 public bool SetOption(ChannelOption option, int value)
 {
     if (option != ChannelOption.MaxPendingBuffers)
     {
         return false;
     }
     if (!this.m_IsReliable)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Cannot set MaxPendingBuffers on unreliable channel " + this.m_ChannelId);
         }
         return false;
     }
     if ((value < 0) || (value >= 0x200))
     {
         if (LogFilter.logError)
         {
             Debug.LogError(string.Concat(new object[] { "Invalid MaxPendingBuffers for channel ", this.m_ChannelId, ". Must be greater than zero and less than ", 0x200 }));
         }
         return false;
     }
     this.m_MaxPendingPacketCount = value;
     return true;
 }
Esempio n. 34
0
 public bool SetChannelOption(int channelId, ChannelOption option, int value)
 {
     if (this.m_Channels == null)
     {
         return false;
     }
     return (((channelId >= 0) && (channelId < this.m_Channels.Length)) && this.m_Channels[channelId].SetOption(option, value));
 }
 /// <summary>
 /// <para>This sets an option on the network channel.</para>
 /// </summary>
 /// <param name="channelId">The channel the option will be set on.</param>
 /// <param name="option">The option to set.</param>
 /// <param name="value">The value for the option.</param>
 /// <returns>
 /// <para>True if the option was set.</para>
 /// </returns>
 public bool SetChannelOption(int channelId, ChannelOption option, int value)
 {
     if (this.m_Channels == null)
     {
         return false;
     }
     if ((channelId < 0) || (channelId >= this.m_Channels.Length))
     {
         return false;
     }
     return this.m_Channels[channelId].SetOption(option, value);
 }