From 66f8dcb1f1580d1812a37c3a17559b0994534f86 Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Thu, 27 Sep 2018 20:41:53 +0200 Subject: [PATCH] HaikuDepot : Improvement for Buffer Management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes the logic flow around reverting the position of the request / response buffers when the buffer is logged during trace logging. Change-Id: I025ca9988b32447e225e3ad1b1d4da1174d2d122 Reviewed-on: https://review.haiku-os.org/599 Reviewed-by: Rene Gollent Reviewed-by: Jérôme Duval --- src/apps/haikudepot/server/WebAppInterface.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/apps/haikudepot/server/WebAppInterface.cpp b/src/apps/haikudepot/server/WebAppInterface.cpp index 3ccc489d4c..c03c8d8293 100644 --- a/src/apps/haikudepot/server/WebAppInterface.cpp +++ b/src/apps/haikudepot/server/WebAppInterface.cpp @@ -750,11 +750,9 @@ WebAppInterface::_SendJsonRequest(const char* domain, BPositionIO* requestData, // delivered from memory. if (Logger::IsTraceEnabled()) { - off_t requestDataPosition = requestData->Position(); printf("jrpc request; "); _LogPayload(requestData, requestDataSize); printf("\n"); - requestData->Seek(requestDataPosition, SEEK_SET); } ProtocolListener listener(Logger::IsTraceEnabled()); @@ -806,19 +804,19 @@ WebAppInterface::_SendJsonRequest(const char* domain, BPositionIO* requestData, return HD_CLIENT_TOO_OLD; default: - printf("json-rpc request to endpoint [.../%s] failed with http " + printf("jrpc request to endpoint [.../%s] failed with http " "status [%" B_PRId32 "]\n", domain, statusCode); return B_ERROR; } + replyData.Seek(0, SEEK_SET); + if (Logger::IsTraceEnabled()) { printf("jrpc response; "); - replyData.Seek(0, SEEK_SET); _LogPayload(&replyData, replyData.BufferLength()); printf("\n"); } - replyData.Seek(0, SEEK_SET); BJsonMessageWriter jsonMessageWriter(reply); BJson::Parse(&replyData, &jsonMessageWriter); status_t status = jsonMessageWriter.ErrorStatus(); @@ -848,6 +846,7 @@ WebAppInterface::_SendJsonRequest(const char* domain, const BString& jsonString, void WebAppInterface::_LogPayload(BPositionIO* requestData, size_t size) { + off_t requestDataOffset = requestData->Position(); char buffer[LOG_PAYLOAD_LIMIT]; if (size > LOG_PAYLOAD_LIMIT) @@ -869,6 +868,8 @@ WebAppInterface::_LogPayload(BPositionIO* requestData, size_t size) if (size == LOG_PAYLOAD_LIMIT) printf("...(continues)"); } + + requestData->Seek(requestDataOffset, SEEK_SET); }