public async Task ProcessAsync() { try { while (KeepAliveCountdown >= 0) { HttpServerRequest request; try { request = await ReadRequestAsync(); } catch (IOException) { break; } if (request == null) { break; } try { // Process the request Context = new HttpContext(this, request); // test if it is an emulated socket EmuPollSocket emuSocket = EmuPollSocket.GetEmuPollSocket(Context); if (emuSocket != null) { await emuSocket.ProcessRequestAsync(Context); } else { await Server.ProcessRequestAsync(Context); } if ((webSocket == null) || (emuSocket != null)) { // in case nobody send the response... if (!Context.Response.Sent) { await HttpSendResponse.SendAsync(Context); } } // process multiple request is not possible with websocket else { break; } } catch (IOException) { break; } finally { // free the response content if ((Context.Response != null) && (Context.Response.Content != null)) { Context.Response.Content.Dispose(); } } Interlocked.Increment(ref requestCounter); } } catch (SocketException) { } finally { stream.Close(); } }