]> git.tdb.fi Git - libs/net.git/commitdiff
Allow creating an Http::Server without immediately listening
authorMikko Rasa <tdb@tdb.fi>
Fri, 27 Sep 2019 21:38:06 +0000 (00:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 27 Sep 2019 21:38:06 +0000 (00:38 +0300)
source/http/server.cpp
source/http/server.h

index 20d2b397bdd474d08010ac9b5e6eb4520386da25..97a42b575477a6f89938d1333ac779db2b03842e 100644 (file)
@@ -17,13 +17,16 @@ using namespace std;
 namespace Msp {
 namespace Http {
 
+Server::Server():
+       sock(Net::INET6),
+       event_disp(0)
+{ }
+
 Server::Server(unsigned port):
        sock(Net::INET6),
        event_disp(0)
 {
-       sock.signal_data_available.connect(sigc::mem_fun(this, &Server::data_available));
-       RefPtr<Net::SockAddr> addr = Net::resolve("*", format("%d", port), Net::INET6);
-       sock.listen(*addr, 8);
+       listen(port);
 }
 
 // Avoid emitting sigc::signal destructor in files including server.h
@@ -31,6 +34,13 @@ Server::~Server()
 {
 }
 
+void Server::listen(unsigned port)
+{
+       RefPtr<Net::SockAddr> addr = Net::resolve("*", format("%d", port), Net::INET6);
+       sock.listen(*addr, 8);
+       sock.signal_data_available.connect(sigc::mem_fun(this, &Server::data_available));
+}
+
 unsigned Server::get_port() const
 {
        const Net::SockAddr &addr = sock.get_local_address();
index 3679013dda51c22c9f76438298b870e069bcd6e1..dd054201d1bf421e136a97c4c2365e8f408cac70 100644 (file)
@@ -37,9 +37,11 @@ private:
        IO::EventDispatcher *event_disp;
 
 public:
+       Server();
        Server(unsigned);
        ~Server();
 
+       void listen(unsigned);
        unsigned get_port() const;
        void use_event_dispatcher(IO::EventDispatcher *);
        void delay_response(Response &);