aboutsummaryrefslogtreecommitdiff
path: root/backends/networking
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-14 09:33:15 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commite25338ec2494c6ae2ff97f231108627635040f76 (patch)
treee2c12f65ed4da7b9c119e0b95ac4b29b09a652e9 /backends/networking
parent1a53dccf51aaf02ca4d0d7a176cca20d385d1ac4 (diff)
downloadscummvm-rg350-e25338ec2494c6ae2ff97f231108627635040f76.tar.gz
scummvm-rg350-e25338ec2494c6ae2ff97f231108627635040f76.tar.bz2
scummvm-rg350-e25338ec2494c6ae2ff97f231108627635040f76.zip
CLOUD: Update CurlJsonRequest
Uses dynamically allocated buffer now.
Diffstat (limited to 'backends/networking')
-rw-r--r--backends/networking/curl/curljsonrequest.cpp14
-rw-r--r--backends/networking/curl/curljsonrequest.h3
2 files changed, 11 insertions, 6 deletions
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index 3bfc823d25..875f5e7fbd 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -32,9 +32,13 @@
namespace Networking {
CurlJsonRequest::CurlJsonRequest(JsonCallback cb, ErrorCallback ecb, Common::String url):
- CurlRequest(nullptr, ecb, url), _jsonCallback(cb), _contentsStream(DisposeAfterUse::YES) {}
+ CurlRequest(nullptr, ecb, url), _jsonCallback(cb), _contentsStream(DisposeAfterUse::YES),
+ _buffer(new byte[CURL_JSON_REQUEST_BUFFER_SIZE]) {}
-CurlJsonRequest::~CurlJsonRequest() { delete _jsonCallback; }
+CurlJsonRequest::~CurlJsonRequest() {
+ delete _jsonCallback;
+ delete[] _buffer;
+}
char *CurlJsonRequest::getPreparedContents() {
//write one more byte in the end
@@ -60,11 +64,9 @@ void CurlJsonRequest::handle() {
if (!_stream) _stream = makeStream();
if (_stream) {
- const int kBufSize = 16*1024;
- char buf[kBufSize+1];
- uint32 readBytes = _stream->read(buf, kBufSize);
+ uint32 readBytes = _stream->read(_buffer, CURL_JSON_REQUEST_BUFFER_SIZE);
if (readBytes != 0)
- if (_contentsStream.write(buf, readBytes) != readBytes)
+ if (_contentsStream.write(_buffer, readBytes) != readBytes)
warning("MemoryWriteStreamDynamic was unable to write all the bytes");
if (_stream->eos()) {
diff --git a/backends/networking/curl/curljsonrequest.h b/backends/networking/curl/curljsonrequest.h
index bd6f135786..5a51065ca9 100644
--- a/backends/networking/curl/curljsonrequest.h
+++ b/backends/networking/curl/curljsonrequest.h
@@ -32,10 +32,13 @@ namespace Networking {
typedef Response<Common::JSONValue *> JsonResponse;
typedef Common::BaseCallback<JsonResponse> *JsonCallback;
+#define CURL_JSON_REQUEST_BUFFER_SIZE 512 * 1024
+
class CurlJsonRequest: public CurlRequest {
protected:
JsonCallback _jsonCallback;
Common::MemoryWriteStreamDynamic _contentsStream;
+ byte *_buffer;
/** Prepares raw bytes from _contentsStream to be parsed with Common::JSON::parse(). */
char *getPreparedContents();