hrev47505 adds 1 changeset to branch 'master' old head: 8f367d30c81b4107020b090c89ebe3c89a289490 new head: 3528905be60b3752b3a99f5c1ce32bb7f74e6be8 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=3528905+%5E8f367d3 ---------------------------------------------------------------------------- 3528905: Parse multiple HTTP at once Instead of relying on the global protocol loop to call _ParseHeaders once for each header, extract as much as possible from the current buffer. This saves memory, avoids useless operations on the socket and various processing steps, and fixes #10245. Also improve the handling of 0-size requests to make sure they terminate properly. [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev47505 Commit: 3528905be60b3752b3a99f5c1ce32bb7f74e6be8 URL: http://cgit.haiku-os.org/haiku/commit/?id=3528905 Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Wed Jul 16 15:34:31 2014 UTC Ticket: https://dev.haiku-os.org/ticket/10245 ---------------------------------------------------------------------------- 1 file changed, 15 insertions(+), 14 deletions(-) src/kits/network/libnetapi/HttpRequest.cpp | 29 +++++++++++++------------- ---------------------------------------------------------------------------- diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index cc4d678..ed28b90 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -653,7 +653,7 @@ BHttpRequest::_MakeRequest() if (index != B_ERROR) bytesTotal = atoi(fHeaders.HeaderAt(index).Value()); else - bytesTotal = 0; + bytesTotal = -1; } } @@ -731,7 +731,7 @@ BHttpRequest::_MakeRequest() } } - if (bytesRead > 0) { + if (bytesRead >= 0) { bytesReceived += bytesRead; if (fListener != NULL) { @@ -749,15 +749,15 @@ BHttpRequest::_MakeRequest() size); bytesUnpacked += size; } - } else { + } else if (bytesRead > 0) { fListener->DataReceived(this, inputTempBuffer, bytesReceived - bytesRead, bytesRead); } fListener->DownloadProgress(this, bytesReceived, - bytesTotal); + std::max((ssize_t)0, bytesTotal)); } - if (bytesTotal > 0 && bytesReceived >= bytesTotal) { + if (bytesTotal >= 0 && bytesReceived >= bytesTotal) { receiveEnd = true; if (decompress) { @@ -854,17 +854,18 @@ void BHttpRequest::_ParseHeaders() { BString currentHeader; - if (_GetLine(currentHeader) == B_ERROR) - return; + while (_GetLine(currentHeader) != B_ERROR) + { + // An empty line means the end of the header section + if (currentHeader.Length() == 0) { + fRequestStatus = kRequestHeadersReceived; + return; + } - // An empty line means the end of the header section - if (currentHeader.Length() == 0) { - fRequestStatus = kRequestHeadersReceived; - return; + _EmitDebug(B_URL_PROTOCOL_DEBUG_HEADER_IN, "%s", + currentHeader.String()); + fHeaders.AddHeader(currentHeader.String()); } - - _EmitDebug(B_URL_PROTOCOL_DEBUG_HEADER_IN, "%s", currentHeader.String()); - fHeaders.AddHeader(currentHeader.String()); }