/// <summary>
        /// Internal factory used for creating new outbound connection transports
        /// </summary>
        /// <param name="remoteAddres">TBD</param>
        /// <exception cref="NotSupportedException">TBD</exception>
        /// <returns>TBD</returns>
        protected ClientBootstrap ClientFactory(Address remoteAddres)
        {
            if (InternalTransport == TransportType.Tcp)
            {
                var addressFamily = Settings.DnsUseIpv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;

                var client = new ClientBootstrap()
                             .Group(_clientEventLoopGroup)
                             .Option(ChannelOption.SoReuseaddr, Settings.TcpReuseAddr)
                             .Option(ChannelOption.SoKeepalive, Settings.TcpKeepAlive)
                             .Option(ChannelOption.TcpNodelay, Settings.TcpNoDelay)
                             .Option(ChannelOption.ConnectTimeout, Settings.ConnectTimeout)
                             .Option(ChannelOption.AutoRead, false)
                             .PreferredDnsResolutionFamily(addressFamily)
                             .ChannelFactory(() => Settings.EnforceIpFamily ?
                                             new TcpSocketChannel(addressFamily) :
                                             new TcpSocketChannel())
                             .Handler(
                    new ActionChannelInitializer <TcpSocketChannel>(
                        channel => SetClientPipeline(channel, remoteAddres)));

                if (Settings.ReceiveBufferSize != null)
                {
                    client.Option(ChannelOption.SoRcvbuf, (int)(Settings.ReceiveBufferSize));
                }
                if (Settings.SendBufferSize != null)
                {
                    client.Option(ChannelOption.SoSndbuf, (int)(Settings.SendBufferSize));
                }
                if (Settings.WriteBufferHighWaterMark != null)
                {
                    client.Option(ChannelOption.WriteBufferHighWaterMark, (int)(Settings.WriteBufferHighWaterMark));
                }
                if (Settings.WriteBufferLowWaterMark != null)
                {
                    client.Option(ChannelOption.WriteBufferLowWaterMark, (int)(Settings.WriteBufferLowWaterMark));
                }

                return(client);
            }

            throw new NotSupportedException("UDP is not supported");
        }
Beispiel #2
0
        /// <summary>
        /// Internal factory used for creating new outbound connection transports
        /// </summary>
        protected ClientBootstrap ClientFactory(Address remoteAddres)
        {
            if (InternalTransport == TransportType.Tcp)
            {
                var addressFamily = Settings.DnsUseIpv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;

                var client = new ClientBootstrap()
                    .Group(_clientEventLoopGroup)
                    .Option(ChannelOption.SoReuseaddr, Settings.TcpReuseAddr)
                    .Option(ChannelOption.SoKeepalive, Settings.TcpKeepAlive)
                    .Option(ChannelOption.TcpNodelay, Settings.TcpNoDelay)
                    .Option(ChannelOption.ConnectTimeout, Settings.ConnectTimeout)
                    .Option(ChannelOption.AutoRead, false)
                    .PreferredDnsResolutionFamily(addressFamily)
                    .ChannelFactory(() => Settings.EnforceIpFamily ? 
                                        new TcpSocketChannel(addressFamily):
                                        new TcpSocketChannel())
                    .Handler(
                        new ActionChannelInitializer<TcpSocketChannel>(
                            channel => SetClientPipeline(channel, remoteAddres)));

                if (Settings.ReceiveBufferSize != null) client.Option(ChannelOption.SoRcvbuf, (int)(Settings.ReceiveBufferSize));
                if (Settings.SendBufferSize != null) client.Option(ChannelOption.SoSndbuf, (int)(Settings.SendBufferSize));
                if (Settings.WriteBufferHighWaterMark != null) client.Option(ChannelOption.WriteBufferHighWaterMark, (int)(Settings.WriteBufferHighWaterMark));
                if (Settings.WriteBufferLowWaterMark != null) client.Option(ChannelOption.WriteBufferLowWaterMark, (int)(Settings.WriteBufferLowWaterMark));

                return client;
            }

            throw new NotSupportedException("UDP is not supported");
        }