aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-14 09:27:08 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit1a53dccf51aaf02ca4d0d7a176cca20d385d1ac4 (patch)
tree5cbf5f7456dca1b02a7cd53b4f77a1d3b6bf5ae3 /backends/cloud
parentb4e9e35e07538a118588742aff6fd4a7a2b4d600 (diff)
downloadscummvm-rg350-1a53dccf51aaf02ca4d0d7a176cca20d385d1ac4.tar.gz
scummvm-rg350-1a53dccf51aaf02ca4d0d7a176cca20d385d1ac4.tar.bz2
scummvm-rg350-1a53dccf51aaf02ca4d0d7a176cca20d385d1ac4.zip
CLOUD: Update DownloadRequest
It now uses a dynamically allocated 1 MB buffer.
Diffstat (limited to 'backends/cloud')
-rw-r--r--backends/cloud/downloadrequest.cpp9
-rw-r--r--backends/cloud/downloadrequest.h3
2 files changed, 7 insertions, 5 deletions
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);