]> git.tdb.fi Git - libs/net.git/blobdiff - source/http/server.h
Prepare for assimilation into mspnet
[libs/net.git] / source / http / server.h
diff --git a/source/http/server.h b/source/http/server.h
new file mode 100644 (file)
index 0000000..41894db
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef MSP_HTTP_SERVER_H_
+#define MSP_HTTP_SERVER_H_
+
+#include <msp/core/refptr.h>
+#include <msp/io/eventdispatcher.h>
+#include <msp/net/streamserversocket.h>
+
+namespace Msp {
+namespace Http {
+
+class Request;
+class Response;
+
+class Server
+{
+public:
+       sigc::signal<void, const Request &, Response &> signal_request;
+
+private:
+       struct Client
+       {
+               RefPtr<Net::StreamSocket> sock;
+               std::string in_buf;
+               Request *request;
+               Response *response;
+               bool async;
+               bool stale;
+
+               Client(RefPtr<Net::StreamSocket>);
+               ~Client();
+       };
+
+       Net::StreamServerSocket sock;
+       std::list<Client> clients;
+       IO::EventDispatcher *event_disp;
+
+public:
+       Server(unsigned);
+       unsigned get_port() const;
+       void use_event_dispatcher(IO::EventDispatcher *);
+       void delay_response(Response &);
+       void submit_response(Response &);
+private:
+       void data_available();
+       void client_data_available(Client &);
+       void client_end_of_file(Client &);
+       Client &get_client_by_response(Response &);
+};
+
+} // namespace Http
+} // namespace Msp
+
+#endif