Пример #1
0
            private void EnableInterest(SocketChannel channel, SocketAsyncOperation op)
            {
                switch (op)
                {
                case SocketAsyncOperation.Accept:
                case SocketAsyncOperation.Receive:
                    Execute(() =>
                    {
                        _read.Add(channel.Socket, channel);
                        if (_read.Count == 1 && _write.Count == 0)      // Start the select loop on initial enable interest
                        {
                            Select();                                   // The select loop will stop itself if no more interested sockets
                        }
                    });
                    break;

                case SocketAsyncOperation.Connect:
                case SocketAsyncOperation.Send:
                    Execute(() =>
                    {
                        _write.Add(channel.Socket, channel);            // Start the select loop on initial enable interest
                        if (_read.Count == 0 && _write.Count == 1)      // The select loop will stop itself if no more interested sockets
                        {
                            Select();
                        }
                    });
                    break;
                }
            }
Пример #2
0
 protected TcpConnection(TcpExt tcp, SocketChannel channel, bool pullMode)
 {
     _tcp              = tcp;
     _channel          = channel;
     _pullMode         = pullMode;
     _readingSuspended = pullMode;
 }
Пример #3
0
            public void Register(SocketChannel channel, SocketAsyncOperation?initialOps, IActorRef channelActor)
            {
                channel.Register(channelActor, initialOps);

                if (initialOps.HasValue)
                {
                    EnableInterest(channel, initialOps.Value);
                }

                channelActor.Tell(new ChannelRegistration(
                                      enableInterest: op => EnableInterest(channel, op),
                                      disableInterest: op => DisableInterest(channel, op)
                                      ));
            }
        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);
        }
Пример #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
            private void DisableInterest(SocketChannel channel, SocketAsyncOperation op)
            {
                switch (op)
                {
                case SocketAsyncOperation.Accept:
                case SocketAsyncOperation.Receive:
                    Execute(() => _read.Remove(channel.Socket));
                    break;

                case SocketAsyncOperation.Connect:
                case SocketAsyncOperation.Send:
                    Execute(() => _write.Remove(channel.Socket));
                    break;
                }
            }
Пример #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
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="channel">TBD</param>
 public FailedRegisterIncoming(SocketChannel channel)
 {
     Channel = channel;
 }
Пример #9
0
 public FailedRegisterIncoming(SocketChannel channel)
 {
     Channel = channel;
 }
Пример #10
0
        internal SocketChannel AcceptServerSideChannel(SocketChannel localServer)
        {
            var promise = new TaskCompletionSource<Socket>();
            var task = promise.Task;

            localServer.Socket.Listen(100);
            localServer.Socket.BeginAccept(ar => promise.SetResult(localServer.Socket.EndAccept(ar)), null);

            Selector.Send(ConnectionActor, SelectionHandler.ChannelConnectable.Instance);

            task.Wait();

            var channel = new SocketChannel(task.Result);
            channel.Register(ChannelProbe, SocketAsyncOperation.None);
            return channel;
        }
Пример #11
0
 public Registration(SocketChannel channel, SocketAsyncOperation? initialOps)
 {
     Channel = channel;
     InitialOps = initialOps;
 }
Пример #12
0
        public void Register(SocketChannel channel, SocketAsyncOperation? initialOps, IActorRef channelActor)
        {
            
            channel.Register(channelActor, initialOps);

            RegisterCallReceiver.Ref.Tell(new TcpConnectionSpec.Registration(channel, initialOps));
        }
Пример #13
0
        public void AbortClose(SocketChannel channel)
        {
            // TODO: Do we need to handle expection like JVM?

            channel.Socket.LingerState = new LingerOption(true, 0);
            channel.Close();
        }
Пример #14
0
 public void Register(SocketChannel channel, SocketAsyncOperation? initialOps, IActorRef channelActor)
 {
     _test._registerCallReceiver.Ref.Tell(initialOps, channelActor);
 }