void OnReadInternal(int nread) { ms.Write(buffer, 0, nread); if (ms.Length > 32768) { SendError("Bad request", 400); Close(true); return; } if (nread == 0) { //if (ms.Length > 0) // SendError (); // Why bother? CloseSocket(); Unbind(); return; } if (ProcessInput(ms)) { if (!context.HaveError) { context.Request.FinishInitialization(); } if (context.HaveError) { SendError(); Close(true); return; } if (!epl.BindContext(context)) { SendError("Invalid host", 400); Close(true); return; } HttpListener listener = epl.Listener; if (last_listener != listener) { RemoveConnection(); listener.AddConnection(this); last_listener = listener; } context_bound = true; listener.RegisterContext(context); return; } BeginReadRequest(); }
private void OnReadInternal(IAsyncResult ares) { //_timer.Change(Timeout.Infinite, Timeout.Infinite); int nread = -1; try { nread = _stream.EndRead(ares); _memoryStream.Write(_buffer, 0, nread); if (_memoryStream.Length > 32768) { SendError("Bad Request", 400); Close(true); return; } } catch { if (_memoryStream != null && _memoryStream.Length > 0) { SendError(); } if (_socket != null) { CloseSocket(); Unbind(); } return; } if (nread == 0) { CloseSocket(); Unbind(); return; } if (ProcessInput(_memoryStream)) { if (!_context.HaveError) { _context.Request.FinishInitialization(); } if (_context.HaveError) { SendError(); Close(true); return; } if (!_epl.BindContext(_context)) { const int NotFoundErrorCode = 404; SendError(HttpStatusDescription.Get(NotFoundErrorCode), NotFoundErrorCode); Close(true); return; } HttpListener listener = _epl.Listener; if (_lastListener != listener) { RemoveConnection(); listener.AddConnection(this); _lastListener = listener; } _contextBound = true; listener.RegisterContext(_context); return; } _stream.BeginRead(_buffer, 0, BufferSize, s_onreadCallback, this); }
void OnReadInternal(IAsyncResult ares) { int nread = -1; try { nread = stream.EndRead(ares); ms.Write(buffer, 0, nread); if (ms.Length > 32768) { SendError("Bad request", 400); Close(true); return; } } catch (Exception ex) { OnReadInternalException(ms, ex); return; } if (nread == 0) { //if (ms.Length > 0) // SendError (); // Why bother? _logger.Debug("Exiting HttpConnection.OnReadInternal because nread=0. ConnectionId: {0}", _connectionId); CloseSocket(); Unbind(); return; } if (ProcessInput(ms)) { if (!context.HaveError) { context.Request.FinishInitialization(); } if (context.HaveError) { SendError(); Close(true); return; } if (!epl.BindContext(context)) { SendError("Invalid host", 400); Close(true); return; } HttpListener listener = context.Listener; if (last_listener != listener) { RemoveConnection(); listener.AddConnection(this); last_listener = listener; } context_bound = true; listener.RegisterContext(context); return; } try { stream.BeginRead(buffer, 0, BufferSize, onread_cb, this); } catch (IOException ex) { OnReadInternalException(ms, ex); } }