Exemple #1
0
        public TcpOutgoingConnection(TcpExt tcp, IActorRef commander, Tcp.Connect connect)
            : base(
                tcp,
                tcp.Settings.OutgoingSocketForceIpv4
                       ? new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { Blocking = false }
                       : new Socket(SocketType.Stream, ProtocolType.Tcp) { Blocking = false },
                connect.PullMode,
                tcp.Settings.WriteCommandsQueueMaxSize >= 0 ? tcp.Settings.WriteCommandsQueueMaxSize : Option <int> .None)
        {
            _commander = commander;
            _connect   = connect;

            SignDeathPact(commander);

            foreach (var option in connect.Options)
            {
                option.BeforeConnect(Socket);
            }

            if (connect.LocalAddress != null)
            {
                Socket.Bind(connect.LocalAddress);
            }

            if (connect.Timeout.HasValue)
            {
                Context.SetReceiveTimeout(connect.Timeout.Value);  //Initiate connection timeout if supplied
            }
        }
        public TcpOutgoingConnection(TcpExt tcp, IChannelRegistry channelRegistry, IActorRef commander, Tcp.Connect connect)
            : base(tcp, SocketChannel.Open().ConfigureBlocking(false), connect.PullMode)
        {
            _channelRegistry = channelRegistry;
            _commander       = commander;
            _connect         = connect;

            Context.Watch(commander);    // sign death pact

            connect.Options.ForEach(_ => _.BeforeConnect(Channel.Socket));
            if (connect.LocalAddress != null)
            {
                Channel.Socket.Bind(connect.LocalAddress);
            }
            channelRegistry.Register(Channel, SocketAsyncOperation.None, Self);
            if (connect.Timeout.HasValue)
            {
                Context.SetReceiveTimeout(connect.Timeout.Value);  //Initiate connection timeout if supplied
            }
        }
        public TcpOutgoingConnection(TcpExt tcp, IActorRef commander, Tcp.Connect connect)
            : base(tcp, new Socket(SocketType.Stream, ProtocolType.Tcp) { Blocking = false }, connect.PullMode)
        {
            _commander = commander;
            _connect   = connect;

            SignDeathPact(commander);

            foreach (var option in connect.Options)
            {
                option.BeforeConnect(Socket);
            }

            if (connect.LocalAddress != null)
            {
                Socket.Bind(connect.LocalAddress);
            }

            if (connect.Timeout.HasValue)
            {
                Context.SetReceiveTimeout(connect.Timeout.Value);  //Initiate connection timeout if supplied
            }
        }