]> git.tdb.fi Git - libs/net.git/blob - source/server.h
Add Server class
[libs/net.git] / source / server.h
1 /* $Id$
2
3 This file is part of libmsphttp
4 Copyright © 2008  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_HTTP_SERVER_H_
9 #define MSP_HTTP_SERVER_H_
10
11 #include <msp/core/refptr.h>
12 #include <msp/io/eventdispatcher.h>
13 #include <msp/net/streamlistensocket.h>
14
15 namespace Msp {
16 namespace Http {
17
18 class Request;
19 class Response;
20
21 class Server
22 {
23 public:
24         sigc::signal<void, const Request &, Response &> signal_request;
25
26 private:
27         struct Client
28         {
29                 RefPtr<Net::StreamSocket> sock;
30                 std::string in_buf;
31                 Request *request;
32                 bool stale;
33
34                 Client(RefPtr<Net::StreamSocket>);
35                 ~Client();
36         };
37
38         Net::StreamListenSocket sock;
39         std::list<Client> clients;
40         IO::EventDispatcher *event_disp;
41
42 public:
43         Server(unsigned);
44         void use_event_dispatcher(IO::EventDispatcher *);
45 private:
46         void data_available();
47         void client_data_available(Client &);
48         void client_end_of_file(Client &);
49 };
50
51 } // namespace Http
52 } // namespace Msp
53
54 #endif