Esempio n. 1
0
        private void StartAcceptingConnectionsCore(IMultiplexedConnectionListener listener)
        {
            // REVIEW: Multiple accept loops in parallel?
            _ = AcceptConnectionsAsync();

            async Task AcceptConnectionsAsync()
            {
                try
                {
                    while (true)
                    {
                        var connection = await listener.AcceptAsync();

                        if (connection == null)
                        {
                            // We're done listening
                            break;
                        }

                        // Add the connection to the connection manager before we queue it for execution
                        var id = Interlocked.Increment(ref _lastConnectionId);
                        var kestrelConnection = new KestrelConnection <MultiplexedConnectionContext>(id, _serviceContext, c => _connectionDelegate(c), connection, Log);

                        _serviceContext.ConnectionManager.AddConnection(id, kestrelConnection);

                        Log.ConnectionAccepted(connection.ConnectionId);

                        ThreadPool.UnsafeQueueUserWorkItem(kestrelConnection, preferLocal: false);
                    }
                }
                catch (Exception ex)
                {
                    // REVIEW: If the accept loop ends should this trigger a server shutdown? It will manifest as a hang
                    Log.LogCritical(0, ex, "The connection listener failed to accept any new connections.");
                }
                finally
                {
                    _acceptLoopTcs.TrySetResult(null);
                }
            }
        }
Esempio n. 2
0
 public GenericMultiplexedConnectionListener(IMultiplexedConnectionListener multiplexedConnectionListener)
 {
     _multiplexedConnectionListener = multiplexedConnectionListener;
 }
Esempio n. 3
0
    public static async ValueTask <MultiplexedConnectionContext> AcceptAndAddFeatureAsync(this IMultiplexedConnectionListener listener)
    {
        var connection = await listener.AcceptAsync();

        connection.Features.Set <IConnectionHeartbeatFeature>(new TestConnectionHeartbeatFeature());
        return(connection);
    }
Esempio n. 4
0
 public Task StartAcceptingConnections(IMultiplexedConnectionListener listener)
 {
     ThreadPool.UnsafeQueueUserWorkItem(StartAcceptingConnectionsCore, listener, preferLocal: false);
     return(_acceptLoopTcs.Task);
 }