HaikuDepot : Improvement for Buffer Management

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 <rene@gollent.com>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Andrew Lindesay 2018-09-27 20:41:53 +02:00 committed by Rene Gollent
parent 88575af1d2
commit 66f8dcb1f1

View File

@ -750,11 +750,9 @@ WebAppInterface::_SendJsonRequest(const char* domain, BPositionIO* requestData,
// delivered from memory. // delivered from memory.
if (Logger::IsTraceEnabled()) { if (Logger::IsTraceEnabled()) {
off_t requestDataPosition = requestData->Position();
printf("jrpc request; "); printf("jrpc request; ");
_LogPayload(requestData, requestDataSize); _LogPayload(requestData, requestDataSize);
printf("\n"); printf("\n");
requestData->Seek(requestDataPosition, SEEK_SET);
} }
ProtocolListener listener(Logger::IsTraceEnabled()); ProtocolListener listener(Logger::IsTraceEnabled());
@ -806,19 +804,19 @@ WebAppInterface::_SendJsonRequest(const char* domain, BPositionIO* requestData,
return HD_CLIENT_TOO_OLD; return HD_CLIENT_TOO_OLD;
default: 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); "status [%" B_PRId32 "]\n", domain, statusCode);
return B_ERROR; return B_ERROR;
} }
replyData.Seek(0, SEEK_SET);
if (Logger::IsTraceEnabled()) { if (Logger::IsTraceEnabled()) {
printf("jrpc response; "); printf("jrpc response; ");
replyData.Seek(0, SEEK_SET);
_LogPayload(&replyData, replyData.BufferLength()); _LogPayload(&replyData, replyData.BufferLength());
printf("\n"); printf("\n");
} }
replyData.Seek(0, SEEK_SET);
BJsonMessageWriter jsonMessageWriter(reply); BJsonMessageWriter jsonMessageWriter(reply);
BJson::Parse(&replyData, &jsonMessageWriter); BJson::Parse(&replyData, &jsonMessageWriter);
status_t status = jsonMessageWriter.ErrorStatus(); status_t status = jsonMessageWriter.ErrorStatus();
@ -848,6 +846,7 @@ WebAppInterface::_SendJsonRequest(const char* domain, const BString& jsonString,
void void
WebAppInterface::_LogPayload(BPositionIO* requestData, size_t size) WebAppInterface::_LogPayload(BPositionIO* requestData, size_t size)
{ {
off_t requestDataOffset = requestData->Position();
char buffer[LOG_PAYLOAD_LIMIT]; char buffer[LOG_PAYLOAD_LIMIT];
if (size > LOG_PAYLOAD_LIMIT) if (size > LOG_PAYLOAD_LIMIT)
@ -869,6 +868,8 @@ WebAppInterface::_LogPayload(BPositionIO* requestData, size_t size)
if (size == LOG_PAYLOAD_LIMIT) if (size == LOG_PAYLOAD_LIMIT)
printf("...(continues)"); printf("...(continues)");
} }
requestData->Seek(requestDataOffset, SEEK_SET);
} }