From 536d7ed6d26fb0c009cb9bbbdddd54e00bb93813 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 22 Dec 2018 14:32:51 +0000 Subject: [PATCH] Replaced some clumsy buffer handling code in the TracktionMarketplaceStatus class --- .../juce_TracktionMarketplaceStatus.cpp | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/modules/juce_product_unlocking/marketplace/juce_TracktionMarketplaceStatus.cpp b/modules/juce_product_unlocking/marketplace/juce_TracktionMarketplaceStatus.cpp index 702a80321f..79d77e3405 100644 --- a/modules/juce_product_unlocking/marketplace/juce_TracktionMarketplaceStatus.cpp +++ b/modules/juce_product_unlocking/marketplace/juce_TracktionMarketplaceStatus.cpp @@ -62,37 +62,19 @@ String TracktionMarketplaceStatus::readReplyFromWebserver (const String& email, if (stream->connect (nullptr)) { - auto* thread = Thread::getCurrentThread(); + auto thread = Thread::getCurrentThread(); + MemoryOutputStream result; - if (thread->threadShouldExit() || stream->isError()) - return {}; - - auto contentLength = stream->getTotalLength(); - auto downloaded = 0; - - const size_t bufferSize = 0x8000; - HeapBlock buffer (bufferSize); - - while (! (stream->isExhausted() || stream->isError() || thread->threadShouldExit())) + while (! (stream->isExhausted() || stream->isError() + || (thread != nullptr && thread->threadShouldExit()))) { - auto max = jmin ((int) bufferSize, contentLength < 0 ? std::numeric_limits::max() - : static_cast (contentLength - downloaded)); - - auto actualBytesRead = stream->read (buffer.get() + downloaded, max - downloaded); + auto bytesRead = result.writeFromInputStream (*stream, 8192); - if (actualBytesRead < 0 || thread->threadShouldExit() || stream->isError()) - break; - - downloaded += actualBytesRead; - - if (downloaded == contentLength) + if (bytesRead < 0) break; } - if (thread->threadShouldExit() || stream->isError() || (contentLength > 0 && downloaded < contentLength)) - return {}; - - return { CharPointer_UTF8 (buffer.get()), static_cast (downloaded) }; + return result.toString(); } return {};