diff --git a/Sming/SmingCore/Network/Http/HttpConnection.cpp b/Sming/SmingCore/Network/Http/HttpConnection.cpp index 46c160c99f..14b68c6791 100644 --- a/Sming/SmingCore/Network/Http/HttpConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpConnection.cpp @@ -404,72 +404,65 @@ int HttpConnection::staticOnChunkComplete(http_parser* parser) void HttpConnection::onReadyToSendData(TcpConnectionEvent sourceEvent) { - debug_d("HttpConnection::onReadyToSendData: waitingQueue.count: %d", waitingQueue->count()); - do { - if(state == eHCS_Sent) { - state = eHCS_Ready; +REENTER: + switch(state) { + case eHCS_Ready: { + HttpRequest* request = waitingQueue->peek(); + if(request == NULL) { + debug_d("Nothing in the waiting queue"); + outgoingRequest = NULL; + break; } - if(state == eHCS_Ready) { - HttpRequest* request = waitingQueue->peek(); - if(request == NULL) { - debug_d("Nothing in the waiting queue"); - outgoingRequest = NULL; + // if the executionQueue is not empty then we have to check if we can pipeline that request + if(executionQueue.count()) { + if(!(request->method == HTTP_GET || request->method == HTTP_HEAD)) { + // if the current request cannot be pipelined -> break; break; } - // if the executionQueue is not empty then we have to check if we can pipeline that request - if(executionQueue.count()) { - if(!(request->method == HTTP_GET || request->method == HTTP_HEAD)) { - // if the current request cannot be pipelined -> break; + // if we have previous request + if(outgoingRequest != NULL) { + if(!(outgoingRequest->method == HTTP_GET || outgoingRequest->method == HTTP_HEAD)) { + // the outgoing request does not allow pipelining break; } - - // if we have previous request - if(outgoingRequest != NULL) { - if(!(outgoingRequest->method == HTTP_GET || outgoingRequest->method == HTTP_HEAD)) { - // the outgoing request does not allow pipelining - break; - } - } - } // executionQueue.count() - - if(!executionQueue.enqueue(request)) { - debug_e("The working queue is full at the moment"); - break; } + } // executionQueue.count() - waitingQueue->dequeue(); - - outgoingRequest = request; - state = eHCS_SendingHeaders; - sendRequestHeaders(request); - + if(!executionQueue.enqueue(request)) { + debug_e("The working queue is full at the moment"); break; } - if(state >= eHCS_StartSending && state < eHCS_Sent) { - if(state == eHCS_SendingHeaders) { - if(stream != NULL && !stream->isFinished()) { - break; - } + waitingQueue->dequeue(); - state = eHCS_StartBody; - } + outgoingRequest = request; + sendRequestHeaders(request); - if(sendRequestBody(outgoingRequest)) { - state = eHCS_Sent; - delete stream; - stream = NULL; - continue; - } + state = eHCS_SendingHeaders; + } + + case eHCS_SendingHeaders: { + if(stream != NULL && !stream->isFinished()) { + break; } - break; + state = eHCS_StartBody; + } - } while(true); + case eHCS_StartBody: + case eHCS_SendingBody: { + if(sendRequestBody(outgoingRequest)) { + state = eHCS_Ready; + delete stream; + stream = NULL; + goto REENTER; + } + } + } // switch(state) TcpClient::onReadyToSendData(sourceEvent); } diff --git a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp index 4240d115e7..8d5735441a 100644 --- a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp @@ -14,7 +14,6 @@ #include "HttpServer.h" #include "TcpServer.h" -#include "../../Services/cWebsocket/websocket.h" #include "WebConstants.h" #include "../../Data/Stream/ChunkedStream.h" @@ -370,48 +369,45 @@ err_t HttpServerConnection::onReceive(pbuf *buf) void HttpServerConnection::onReadyToSendData(TcpConnectionEvent sourceEvent) { - if(state == eHCS_Sent) { - state = eHCS_Ready; + switch(state) { + case eHCS_StartSending: { + sendResponseHeaders(&response); + state = eHCS_SendingHeaders; } - do { - - if(!(state >= eHCS_StartSending && state < eHCS_Sent)) { + case eHCS_SendingHeaders: { + if (stream != NULL && !stream->isFinished()) { break; } - if(state == eHCS_StartSending) { - sendResponseHeaders(&response); - state = eHCS_SendingHeaders; + state = eHCS_StartBody; + } + + case eHCS_StartBody: + case eHCS_SendingBody: { + if(!sendResponseBody(&response)) { break; } - if(state == eHCS_SendingHeaders) { - if(stream != NULL && !stream->isFinished()) { - break; - } - - state = eHCS_StartBody; - } + delete stream; + stream = NULL; + state = eHCS_Sent; + } - if(sendResponseBody(&response)) { - delete stream; - stream = NULL; - state = eHCS_Sent; + case eHCS_Sent: { + if(response.headers["Connection"] == "close") { + setTimeOut(1); // decrease the timeout to 1 tick } - break; + response.reset(); + request.reset(); - } while(false); + state = eHCS_Ready; - if(state == eHCS_Sent && response.headers["Connection"] == "close") { - setTimeOut(1); // decrease the timeout to 1 tick + break; } - if(state == eHCS_Sent) { - response.reset(); - request.reset(); - } + } /* switch(state) */ TcpClient::onReadyToSendData(sourceEvent); }