From 3bea0872d89d4e980d1df6a24298bbb7f8e101fb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 28 Sep 2019 00:38:06 +0300 Subject: [PATCH] Allow creating an Http::Server without immediately listening --- source/http/server.cpp | 16 +++++++++++++--- source/http/server.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) 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 &); -- 2.45.2