private static void HandleError(Exception e, HttpReaderState httpReaderState) { if (httpReaderState != null) { if (httpReaderState.HttpInboundSocketPipe != null) { httpReaderState.HttpInboundSocketPipe.HandleError(e); } httpReaderState.Dispose(); } }
private static void BeginReceive(HttpReaderState httpReaderState) { try { if (httpReaderState != null && httpReaderState.Socket == null) { httpReaderState.Dispose(); return; } httpReaderState.Socket.BeginReceive(httpReaderState.ReceiveBuffer, 0, httpReaderState.ReceiveBuffer.Length, SocketFlags.None, ascDataReceived, httpReaderState); } catch (Exception e) { HandleError(e, httpReaderState); } }
private static void OnDataReceivedCallback(IAsyncResult asyn) { HttpReaderState httpReaderState = asyn.AsyncState as HttpReaderState; try { if (httpReaderState.Socket != null && httpReaderState.Socket.Connected && OnData(httpReaderState, httpReaderState.ReceiveBuffer, 0, httpReaderState.Socket.EndReceive(asyn), (httpReaderState.Socket != null) ? httpReaderState.Socket.Available : 0)) { BeginReceive(httpReaderState); } else { httpReaderState.HttpInboundSocketPipe.Flush(); httpReaderState.Dispose(); } } catch (Exception e) { HandleError(e, httpReaderState); } }