aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/sdl_net/client.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-15 23:54:53 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit13c54f66850226a516da0450b633ebafbc26584e (patch)
tree5c2582cc47296bee1fd3dc7e8f55bddb102bc61f /backends/networking/sdl_net/client.cpp
parent99c51380fdc866ce393c52eb41803a9ec119a9ad (diff)
downloadscummvm-rg350-13c54f66850226a516da0450b633ebafbc26584e.tar.gz
scummvm-rg350-13c54f66850226a516da0450b633ebafbc26584e.tar.bz2
scummvm-rg350-13c54f66850226a516da0450b633ebafbc26584e.zip
CLOUD: Add GetClientHandler
That ClientHandler is made for responding GET requests. It calculates stream's length, it allows to specify response code and headers, it can be used to transfer any ReadStream.
Diffstat (limited to 'backends/networking/sdl_net/client.cpp')
-rw-r--r--backends/networking/sdl_net/client.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/backends/networking/sdl_net/client.cpp b/backends/networking/sdl_net/client.cpp
index 8ab9ed385e..22bfb60a2f 100644
--- a/backends/networking/sdl_net/client.cpp
+++ b/backends/networking/sdl_net/client.cpp
@@ -28,9 +28,9 @@
namespace Networking {
-Client::Client(): _state(INVALID), _set(nullptr), _socket(nullptr) {}
+Client::Client(): _state(INVALID), _set(nullptr), _socket(nullptr), _handler(nullptr) {}
-Client::Client(SDLNet_SocketSet set, TCPsocket socket): _state(INVALID), _set(nullptr), _socket(nullptr) {
+Client::Client(SDLNet_SocketSet set, TCPsocket socket): _state(INVALID), _set(nullptr), _socket(nullptr), _handler(nullptr) {
open(set, socket);
}
@@ -74,8 +74,7 @@ void Client::checkIfHeadersEnded() {
if (position) _state = READ_HEADERS;
}
-void Client::checkIfBadRequest() {
- if (_state != READING_HEADERS) return;
+void Client::checkIfBadRequest() {
uint32 headersSize = _headers.size();
bool bad = false;
@@ -114,6 +113,18 @@ void Client::checkIfBadRequest() {
if (bad) _state = BAD_REQUEST;
}
+void Client::setHandler(ClientHandler *handler) {
+ if (_handler) delete _handler;
+ _state = BEING_HANDLED;
+ _handler = handler;
+}
+
+void Client::handle() {
+ if (_state != BEING_HANDLED) warning("handle() called in a wrong Client's state");
+ if (!_handler) warning("Client doesn't have handler to be handled by");
+ if (_handler) _handler->handle(this);
+}
+
void Client::close() {
if (_set) {
if (_socket) {
@@ -137,4 +148,10 @@ ClientState Client::state() { return _state; }
Common::String Client::headers() { return _headers; }
+bool Client::socketIsReady() { return SDLNet_SocketReady(_socket); }
+
+int Client::recv(void *data, int maxlen) { return SDLNet_TCP_Recv(_socket, data, maxlen); }
+
+int Client::send(void *data, int len) { return SDLNet_TCP_Send(_socket, data, len); }
+
} // End of namespace Networking