From: Mikko Rasa Date: Fri, 27 Sep 2019 21:38:06 +0000 (+0300) Subject: Allow creating an Http::Server without immediately listening X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3bea0872d89d4e980d1df6a24298bbb7f8e101fb;p=libs%2Fnet.git Allow creating an Http::Server without immediately listening --- diff --git a/source/http/server.cpp b/source/http/server.cpp index 20d2b39..97a42b5 100644 --- a/source/http/server.cpp +++ b/source/http/server.cpp @@ -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 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 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(); diff --git a/source/http/server.h b/source/http/server.h index 3679013..dd05420 100644 --- a/source/http/server.h +++ b/source/http/server.h @@ -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 &);