示例#1
0
        private async Task AcceptLoopAsync(ISocketConfiguration socketConfiguration, CancellationToken cancellationToken, NodeType nodeType)
        {
            _started.Set();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var tcpClient = await _listener.AcceptTcpClientAsync();
                    SetupTcpClientParametersWithoutReceiveTimeout(tcpClient, socketConfiguration);
                    tcpClient.ReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType) ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0;

                    var socket = new TcpSocket(_endpoint, tcpClient);
                    socket.Disconnected += () => ClientDisconnected(socket);

                    TryFireClientConnectedEvent(socket, socketConfiguration);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (OperationCanceledException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
            finally
            {
                _stopped.Set();
            }
        }
示例#2
0
        private async Task AcceptLoopAsync(ISocketConfiguration socketConfiguration, CancellationToken cancellationToken, NodeType nodeType)
        {
            _started.Set();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var tcpClient = await _listener.AcceptTcpClientAsync();

                    SetupTcpClientParametersWithoutReceiveTimeout(tcpClient, socketConfiguration);
                    tcpClient.ReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType) ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0;

                    var socket = new TcpSocket(_endpoint, tcpClient);
                    socket.Disconnected += () => ClientDisconnected(socket);

                    TryFireClientConnectedEvent(socket, socketConfiguration);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (OperationCanceledException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
            finally
            {
                _stopped.Set();
            }
        }
        public void TcpSocket_maps_to_MessageFrameQueueWriter()
        {
            var port = TestHelpers.GetFreePort();
            
            var server = new TcpListener(IPAddress.Loopback, port);
            server.Start();
            server.AcceptSocketAsync();
            
            using (var client = new TcpClient())
            {
                client.Connect(IPAddress.Loopback, port);
                var socket = new TcpSocket(new RedFoxEndpoint(), client);

                var factory = new MessageFrameWriterFactory();
                var writer = factory.CreateWriterFromSocket(socket);

                Assert.IsInstanceOf<MessageFrameStreamWriter>(writer);
            }
        }