aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-09 17:11:40 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit30430b379fa373c277c3a64cfa03aa108b560476 (patch)
treeae6878851d608c47d79791f8208620b056e9d8d5 /backends
parent36b0069e95a5eb6816e75bb9cf4aae56c7b5b258 (diff)
downloadscummvm-rg350-30430b379fa373c277c3a64cfa03aa108b560476.tar.gz
scummvm-rg350-30430b379fa373c277c3a64cfa03aa108b560476.tar.bz2
scummvm-rg350-30430b379fa373c277c3a64cfa03aa108b560476.zip
CLOUD: Fix Client's buffer
Diffstat (limited to 'backends')
-rw-r--r--backends/networking/sdl_net/client.cpp15
-rw-r--r--backends/networking/sdl_net/client.h3
2 files changed, 12 insertions, 6 deletions
diff --git a/backends/networking/sdl_net/client.cpp b/backends/networking/sdl_net/client.cpp
index 3b3f45baaa..9d49480334 100644
--- a/backends/networking/sdl_net/client.cpp
+++ b/backends/networking/sdl_net/client.cpp
@@ -29,14 +29,19 @@
namespace Networking {
-Client::Client() : _state(INVALID), _set(nullptr), _socket(nullptr), _handler(nullptr), _previousHandler(nullptr), _stream(nullptr) {}
+Client::Client():
+ _state(INVALID), _set(nullptr), _socket(nullptr), _handler(nullptr),
+ _previousHandler(nullptr), _stream(nullptr), _buffer(new byte[CLIENT_BUFFER_SIZE]) {}
-Client::Client(SDLNet_SocketSet set, TCPsocket socket) : _state(INVALID), _set(nullptr), _socket(nullptr), _handler(nullptr), _previousHandler(nullptr), _stream(nullptr) {
+Client::Client(SDLNet_SocketSet set, TCPsocket socket):
+ _state(INVALID), _set(nullptr), _socket(nullptr), _handler(nullptr),
+ _previousHandler(nullptr), _stream(nullptr), _buffer(new byte[CLIENT_BUFFER_SIZE]) {
open(set, socket);
}
Client::~Client() {
close();
+ delete[] _buffer;
}
void Client::open(SDLNet_SocketSet set, TCPsocket socket) {
@@ -65,16 +70,14 @@ bool Client::readMoreIfNeeded() {
if (!_socket) return false;
if (!SDLNet_SocketReady(_socket)) return false;
- const uint32 BUFFER_SIZE = 16 * 1024;
- byte buffer[BUFFER_SIZE];
- int bytes = SDLNet_TCP_Recv(_socket, buffer, BUFFER_SIZE);
+ int bytes = SDLNet_TCP_Recv(_socket, _buffer, CLIENT_BUFFER_SIZE);
if (bytes <= 0) {
warning("Client::readHeaders recv fail");
close();
return false;
}
- if (_stream->write(buffer, bytes) != bytes) {
+ if (_stream->write(_buffer, bytes) != bytes) {
warning("failed to write() into MemoryReadWriteStream");
close();
return false;
diff --git a/backends/networking/sdl_net/client.h b/backends/networking/sdl_net/client.h
index 22e450a6a8..f37d04658c 100644
--- a/backends/networking/sdl_net/client.h
+++ b/backends/networking/sdl_net/client.h
@@ -45,6 +45,8 @@ enum ClientState {
class Client;
+#define CLIENT_BUFFER_SIZE 1 * 1024 * 1024
+
class ClientHandler {
public:
virtual ~ClientHandler() {};
@@ -58,6 +60,7 @@ class Client {
Reader _reader;
ClientHandler *_handler, *_previousHandler;
Common::MemoryReadWriteStream *_stream;
+ byte *_buffer;
bool readMoreIfNeeded();