From 1a53dccf51aaf02ca4d0d7a176cca20d385d1ac4 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 09:27:08 +0600 Subject: CLOUD: Update DownloadRequest It now uses a dynamically allocated 1 MB buffer. --- backends/cloud/downloadrequest.cpp | 9 ++++----- backends/cloud/downloadrequest.h | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'backends/cloud') diff --git a/backends/cloud/downloadrequest.cpp b/backends/cloud/downloadrequest.cpp index c95b8b81af..43bb02a756 100644 --- a/backends/cloud/downloadrequest.cpp +++ b/backends/cloud/downloadrequest.cpp @@ -29,7 +29,7 @@ namespace Cloud { DownloadRequest::DownloadRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb, Common::String remoteFileId, Common::DumpFile *dumpFile): Request(nullptr, ecb), _boolCallback(callback), _localFile(dumpFile), _remoteFileId(remoteFileId), _storage(storage), - _remoteFileStream(nullptr), _workingRequest(nullptr), _ignoreCallback(false) { + _remoteFileStream(nullptr), _workingRequest(nullptr), _ignoreCallback(false), _buffer(new byte[DOWNLOAD_REQUEST_BUFFER_SIZE]) { start(); } @@ -38,6 +38,7 @@ DownloadRequest::~DownloadRequest() { if (_workingRequest) _workingRequest->finish(); delete _boolCallback; delete _localFile; + delete[] _buffer; } void DownloadRequest::start() { @@ -84,12 +85,10 @@ void DownloadRequest::handle() { return; } - const int kBufSize = 640 * 1024; //640 KB is enough to everyone?.. - char buf[kBufSize]; - uint32 readBytes = _remoteFileStream->read(buf, kBufSize); + uint32 readBytes = _remoteFileStream->read(_buffer, DOWNLOAD_REQUEST_BUFFER_SIZE); if (readBytes != 0) - if (_localFile->write(buf, readBytes) != readBytes) { + if (_localFile->write(_buffer, readBytes) != readBytes) { warning("DownloadRequest: unable to write all received bytes into output file"); finishError(Networking::ErrorResponse(this, false, true, "", -1)); return; diff --git a/backends/cloud/downloadrequest.h b/backends/cloud/downloadrequest.h index d8e18f9171..99b7de37f0 100644 --- a/backends/cloud/downloadrequest.h +++ b/backends/cloud/downloadrequest.h @@ -30,6 +30,8 @@ namespace Cloud { +#define DOWNLOAD_REQUEST_BUFFER_SIZE 1 * 1024 * 1024 + class DownloadRequest: public Networking::Request { Storage::BoolCallback _boolCallback; Common::DumpFile *_localFile; @@ -38,6 +40,7 @@ class DownloadRequest: public Networking::Request { Networking::NetworkReadStream *_remoteFileStream; Request *_workingRequest; bool _ignoreCallback; + byte *_buffer; void start(); void streamCallback(Networking::NetworkReadStreamResponse response); -- cgit v1.2.3