예제 #1
0
    public static async ValueTask <MultiplexedConnectionContext> AcceptAndAddFeatureAsync(this IMultiplexedConnectionListener listener)
    {
        var connection = await listener.AcceptAsync();

        connection.Features.Set <IConnectionHeartbeatFeature>(new TestConnectionHeartbeatFeature());
        return(connection);
    }
예제 #2
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);
                }
            }
        }
예제 #3
0
 public ValueTask <MultiplexedConnectionContext?> AcceptAsync(CancellationToken cancellationToken = default)
 => _multiplexedConnectionListener.AcceptAsync(features: null, cancellationToken);