public async ValueTask <ConnectionContext> AcceptAsync(CancellationToken cancellationToken = default) { if (this.Listener == null) { throw new ApplicationException("Listener is not bound yet."); } ConnSock sock = await this.Listener.AcceptNextSocketFromQueueUtilAsync(cancellationToken); var connection = new KestrelStackConnection(sock); connection.Start(); return(connection); }
async Task ListenerAcceptNewSocketCallback(NetTcpListenerPort listener, ConnSock newSock) { using (var connection = new KestrelStackConnection(newSock, this.PipeScheduler)) { // Note: // In ASP.NET Core 2.2 or higher, Dispatcher.OnConnection() will return Task. // Otherwise, Dispatcher.OnConnection() will return void. // Then we need to use the reflection to call the OnConnection() method indirectly. Task?middlewareTask = Dispatcher._PrivateInvoke("OnConnection", connection) as Task; // Wait for transport to end await connection.StartAsync(); // Wait for middleware to end if (middlewareTask != null) { await middlewareTask; } connection._DisposeSafe(); } }