private async Task SendResponse(TcpReceiveContext state, TcpResponse tcpResponse) { var content = tcpResponse.GetSendStream(); DebugOutput.Log("Sending response ({0} bytes)", content.Length); var sockStream = new AsyncSocketWriterReader(state.ClientSocket); await sockStream.WriteAsync(content, tcpResponse.Header); }
private async Task<bool> Process(TcpReceiveContext state, TcpResponse response) { Stream requestBody; if (state.Header.ContentLength > 0) { state.ReceivedData.Position = 0; requestBody = _compression.DecompressFrom(state.ReceivedData); } else { requestBody = Stream.Null; } var context = new OwinContext(new TcpRequest(state.Header, requestBody), response, GetUriEndpoint(state.ClientSocket.RemoteEndPoint)); state.Cleanup.Add(response); state.Cleanup.Add(requestBody); return await Process(context); }
private async Task<bool> ExecuteRequest(TcpReceiveContext state, TcpResponse tcpResponse) { bool continueReceive = false; try { continueReceive = await Process(state, tcpResponse); } catch (AggregateException ex) { if (ex.InnerException is SocketException) { _transportError = true; } if (!HandleTransportError(ex)) { throw; } } catch (Exception ex) { if (!await HandleRequestError(ex, tcpResponse)) { throw; } } await SendResponse(state, tcpResponse); return continueReceive; }