コード例 #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));
        }
コード例 #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
            }
        }
コード例 #3
0
ファイル: TcpConnection.cs プロジェクト: zhanjian/akka.net
 protected TcpConnection(TcpExt tcp, SocketChannel channel, bool pullMode)
 {
     _tcp              = tcp;
     _channel          = channel;
     _pullMode         = pullMode;
     _readingSuspended = pullMode;
 }
コード例 #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
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: TcpConnection.cs プロジェクト: xyicheng/akka.net
        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;
        }
コード例 #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
            }
        }
コード例 #8
0
        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
            }
        }
コード例 #9
0
ファイル: TcpManager.cs プロジェクト: icewwn/akka.net
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="tcp">TBD</param>
 public TcpManager(TcpExt tcp)
 {
     _tcp = tcp;
     Context.System.EventStream.Subscribe(Self, typeof(DeadLetter));
 }
コード例 #10
0
 public TcpManager(TcpExt tcp)
     : base(tcp.Settings, tcp.Settings.NrOfSelectors)
 {
     _tcp = tcp;
 }