]> git.tdb.fi Git - libs/net.git/blob - source/http/server.h
29b2b45a3d4cb95ad35a529139a64834e2e3c657
[libs/net.git] / source / http / server.h
1 #ifndef MSP_HTTP_SERVER_H_
2 #define MSP_HTTP_SERVER_H_
3
4 #include <msp/core/refptr.h>
5 #include <msp/io/eventdispatcher.h>
6 #include <msp/net/streamserversocket.h>
7
8 namespace Msp {
9 namespace Http {
10
11 class Request;
12 class Response;
13
14 class Server
15 {
16 public:
17         sigc::signal<void, const Request &, Response &> signal_request;
18
19 private:
20         struct Client
21         {
22                 RefPtr<Net::StreamSocket> sock;
23                 std::string in_buf;
24                 Request *request;
25                 Response *response;
26                 bool keepalive;
27                 bool async;
28                 bool stale;
29
30                 Client(RefPtr<Net::StreamSocket>);
31                 ~Client();
32         };
33
34         Net::StreamServerSocket sock;
35         std::list<Client> clients;
36         std::map<Response *, Client *> responses;
37         IO::EventDispatcher *event_disp;
38
39 public:
40         Server(unsigned);
41         ~Server();
42
43         unsigned get_port() const;
44         void use_event_dispatcher(IO::EventDispatcher *);
45         void delay_response(Response &);
46         void submit_response(Response &);
47 private:
48         void data_available();
49         void client_data_available(Client &);
50         void send_response(Client &, Response &);
51         void client_end_of_file(Client &);
52         Client &get_client_by_response(Response &);
53 };
54
55 } // namespace Http
56 } // namespace Msp
57
58 #endif