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.
This commit is contained in:
Alexander Tkachev 2016-06-15 23:54:53 +06:00
parent 99c51380fd
commit 13c54f6685
7 changed files with 212 additions and 9 deletions

View file

@ -35,7 +35,16 @@ enum ClientState {
INVALID,
READING_HEADERS,
READ_HEADERS,
BAD_REQUEST
BAD_REQUEST,
BEING_HANDLED
};
class Client;
class ClientHandler {
public:
virtual ~ClientHandler() {};
virtual void handle(Client *client) = 0;
};
class Client {
@ -43,6 +52,7 @@ class Client {
SDLNet_SocketSet _set;
TCPsocket _socket;
Common::String _headers;
ClientHandler *_handler;
void checkIfHeadersEnded();
void checkIfBadRequest();
@ -54,10 +64,23 @@ public:
void open(SDLNet_SocketSet set, TCPsocket socket);
void readHeaders();
void setHandler(ClientHandler *handler);
void handle();
void close();
ClientState state();
Common::String headers();
/**
* Return SDLNet_SocketReady(_socket).
*
* It's "ready" when it has something
* to read (recv()). You can send()
* when this is false.
*/
bool socketIsReady();
int recv(void *data, int maxlen);
int send(void *data, int len);
};
} // End of namespace Networking