Example #1
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="tcp">TBD</param>
        /// <param name="bindCommander">TBD</param>
        /// <param name="bind">TBD</param>
        public TcpListener(TcpExt tcp, IActorRef bindCommander,
                           Tcp.Bind bind)
        {
            _tcp           = tcp;
            _bindCommander = bindCommander;
            _bind          = bind;

            Context.Watch(bind.Handler);

            _socket = new Socket(_bind.LocalAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            {
                Blocking = false
            };

            _acceptLimit = bind.PullMode ? 0 : _tcp.Settings.BatchAcceptLimit;

            try
            {
                bind.Options.ForEach(x => x.BeforeServerSocketBind(_socket));
                _socket.Bind(bind.LocalAddress);
                _socket.Listen(bind.Backlog);
                _saeas = Accept(_acceptLimit).ToArray();
            }
            catch (Exception e)
            {
                _bindCommander.Tell(bind.FailureMessage);
                _log.Error(e, "Bind failed for TCP channel on endpoint [{0}]", bind.LocalAddress);
                Context.Stop(Self);
            }

            bindCommander.Tell(new Tcp.Bound(_socket.LocalEndPoint));
        }
Example #2
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
            }
        }
Example #3
0
 protected TcpConnection(TcpExt tcp, SocketChannel channel, bool pullMode)
 {
     _tcp              = tcp;
     _channel          = channel;
     _pullMode         = pullMode;
     _readingSuspended = pullMode;
 }
Example #4
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="tcp">TBD</param>
        /// <param name="socket">TBD</param>
        /// <param name="bindHandler">TBD</param>
        /// <param name="options">TBD</param>
        /// <param name="readThrottling">TBD</param>
        public TcpIncomingConnection(TcpExt tcp,
                                     Socket socket,
                                     IActorRef bindHandler,
                                     IEnumerable <Inet.SocketOption> options,
                                     bool readThrottling)
            : base(tcp, socket, readThrottling)
        {
            _bindHandler = bindHandler;
            _options     = options;

            Context.Watch(bindHandler); // sign death pact
        }
        public TcpIncomingConnection(TcpExt tcp,
                                     SocketChannel channel,
                                     IChannelRegistry registry,
                                     IActorRef bindHandler,
                                     IEnumerable <Inet.SocketOption> options,
                                     bool readThrottling)
            : base(tcp, channel, readThrottling)
        {
            _bindHandler = bindHandler;
            _options     = options;

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

            registry.Register(channel, SocketAsyncOperation.None, Self);
        }
Example #6
0
        protected TcpConnection(TcpExt tcp, Socket socket, bool pullMode)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }

            Tcp           = tcp;
            Socket        = socket;
            this.pullMode = pullMode;
            if (pullMode)
            {
                SetStatus(ConnectionStatus.ReadingSuspended);
            }
            traceLogging = tcp.Settings.TraceLogging;
        }
Example #7
0
        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
            }
        }
Example #9
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="tcp">TBD</param>
 public TcpManager(TcpExt tcp)
 {
     _tcp = tcp;
     Context.System.EventStream.Subscribe(Self, typeof(DeadLetter));
 }
Example #10
0
 public TcpManager(TcpExt tcp)
     : base(tcp.Settings, tcp.Settings.NrOfSelectors)
 {
     _tcp = tcp;
 }