]> git.tdb.fi Git - libs/net.git/blobdiff - source/http/server.h
Use std::unique_ptr for owning pointers
[libs/net.git] / source / http / server.h
index 29b2b45a3d4cb95ad35a529139a64834e2e3c657..dd8b2c6c88589bd4b453b9fc48c7275fee277b9c 100644 (file)
@@ -1,9 +1,9 @@
 #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>
+#include <msp/time/timedelta.h>
 
 namespace Msp {
 namespace Http {
@@ -19,31 +19,34 @@ public:
 private:
        struct Client
        {
-               RefPtr<Net::StreamSocket> sock;
+               std::unique_ptr<Net::StreamSocket> sock;
                std::string in_buf;
-               Request *request;
-               Response *response;
-               bool keepalive;
-               bool async;
-               bool stale;
-
-               Client(RefPtr<Net::StreamSocket>);
-               ~Client();
+               std::unique_ptr<Request> request;
+               std::unique_ptr<Response> response;
+               bool keepalive = false;
+               bool async = false;
+               bool stale = false;
+
+               Client(std::unique_ptr<Net::StreamSocket>);
        };
 
        Net::StreamServerSocket sock;
        std::list<Client> clients;
        std::map<Response *, Client *> responses;
-       IO::EventDispatcher *event_disp;
+       IO::EventDispatcher *event_disp = nullptr;
 
 public:
+       Server();
        Server(unsigned);
        ~Server();
 
+       void listen(unsigned);
        unsigned get_port() const;
        void use_event_dispatcher(IO::EventDispatcher *);
        void delay_response(Response &);
        void submit_response(Response &);
+       void cancel_keepalive(Response &);
+       void close_connections(const Time::TimeDelta &);
 private:
        void data_available();
        void client_data_available(Client &);