Пример #1
0
        private async Task RunAcceptLoopAsync()
        {
            try
            {
                while (true)
                {
                    for (var schedulerIndex = 0; schedulerIndex < _numSchedulers; schedulerIndex++)
                    {
                        try
                        {
                            var acceptSocket = await _listenSocket.AcceptAsync();

                            acceptSocket.NoDelay = _endPointInformation.NoDelay;

                            var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace);

                            // REVIEW: This task should be tracked by the server for graceful shutdown
                            // Today it's handled specifically for http but not for aribitrary middleware
                            _ = HandleConnectionAsync(connection);
                        }
                        catch (SocketException ex) when(ex.SocketErrorCode == SocketError.ConnectionReset)
                        {
                            // REVIEW: Should there be a separate log message for a connection reset this early?
                            _trace.ConnectionReset(connectionId: "(null)");
                        }
                        catch (SocketException ex) when(!_unbinding)
                        {
                            _trace.ConnectionError(connectionId: "(null)", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_unbinding)
                {
                    // Means we must be unbinding. Eat the exception.
                }
                else
                {
                    _trace.LogCritical(ex, $"Unexpected exception in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}.");
                    _listenException = ex;

                    // Request shutdown so we can rethrow this exception
                    // in Stop which should be observable.
                    _appLifetime.StopApplication();
                }
            }
        }
Пример #2
0
        private async Task RunAcceptLoopAsync()
        {
            try
            {
                while (true)
                {
                    for (var schedulerIndex = 0; schedulerIndex < _numSchedulers; schedulerIndex++)
                    {
                        try
                        {
                            var acceptSocket = await _listenSocket.AcceptAsync();

                            acceptSocket.NoDelay = _endPointInformation.NoDelay;

                            var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace);
                            HandleConnectionAsync(connection);
                        }
                        catch (SocketException) when(!_unbinding)
                        {
                            _trace.ConnectionReset(connectionId: "(null)");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_unbinding)
                {
                    // Means we must be unbinding. Eat the exception.
                }
                else
                {
                    _trace.LogCritical(ex, $"Unexpected exception in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}.");
                    _listenException = ex;

                    // Request shutdown so we can rethrow this exception
                    // in Stop which should be observable.
                    _appLifetime.StopApplication();
                }
            }
        }
        private async Task RunAcceptLoopAsync()
        {
            try
            {
                while (true)
                {
                    try
                    {
                        var acceptSocket = await _listenSocket.AcceptAsync();

                        acceptSocket.NoDelay = _endPointInformation.NoDelay;

                        var connection = new SocketConnection(acceptSocket, _memoryPool, _trace);
                        _ = connection.StartAsync(_handler);
                    }
                    catch (SocketException ex) when(ex.SocketErrorCode == SocketError.ConnectionReset)
                    {
                        // REVIEW: Should there be a seperate log message for a connection reset this early?
                        _trace.ConnectionReset(connectionId: "(null)");
                    }
                    catch (SocketException ex) when(!_unbinding)
                    {
                        _trace.ConnectionError(connectionId: "(null)", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                if (_unbinding)
                {
                    // Means we must be unbinding. Eat the exception.
                }
                else
                {
                    _trace.LogCritical(ex, $"Unexpected exeption in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}.");
                    _listenException = ex;

                    // Request shutdown so we can rethrow this exception
                    // in Stop which should be observable.
                    _appLifetime.StopApplication();
                }
            }
        }