From 5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 27 Sep 2013 21:28:41 +0200 Subject: Added cHTTPServer callbacks; fixed keep-alives. The HTTP server now calls callbacks specified in its start function (debugified atm.) and it processes multiple requests on a single connection. --- source/HTTPServer/HTTPConnection.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source/HTTPServer/HTTPConnection.cpp') diff --git a/source/HTTPServer/HTTPConnection.cpp b/source/HTTPServer/HTTPConnection.cpp index 2265d970f..c36b07d3d 100644 --- a/source/HTTPServer/HTTPConnection.cpp +++ b/source/HTTPServer/HTTPConnection.cpp @@ -69,6 +69,39 @@ void cHTTPConnection::FinishResponse(void) +void cHTTPConnection::AwaitNextRequest(void) +{ + switch (m_State) + { + case wcsRecvIdle: + { + // The client is waiting for a response, send an "Internal server error": + m_OutgoingData.append("HTTP/1.1 500 Internal Server Error\r\n\r\n"); + m_HTTPServer.NotifyConnectionWrite(*this); + m_State = wcsRecvHeaders; + break; + } + + case wcsSendingResp: + { + // The response headers have been sent, we need to terminate the response body: + m_OutgoingData.append("0\r\n\r\n"); + m_State = wcsRecvHeaders; + break; + } + + default: + { + ASSERT(!"Unhandled state recovery"); + break; + } + } +} + + + + + void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) { switch (m_State) @@ -128,10 +161,10 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) } if (m_CurrentRequestBodyRemaining == 0) { + m_State = wcsRecvIdle; m_HTTPServer.RequestFinished(*this, *m_CurrentRequest); delete m_CurrentRequest; m_CurrentRequest = NULL; - m_State = wcsRecvIdle; } break; } -- cgit v1.2.3