diff --git a/src/HTTPServer.cc b/src/HTTPServer.cc index bb1c2e6a..c09d004b 100644 --- a/src/HTTPServer.cc +++ b/src/HTTPServer.cc @@ -162,12 +162,18 @@ const string& HTTPServer::get_url_param( return range.first->second; } -HTTPServer::HTTPServer(shared_ptr state) - : state(state), - base(event_base_new(), event_base_free), - http(evhttp_new(this->base.get()), evhttp_free), - th(&HTTPServer::thread_fn, this) { +HTTPServer::HTTPServer(shared_ptr state, shared_ptr shared_base) + : state(state) { + if (!shared_base) { + this->base.reset(event_base_new(), event_base_free); + } else { + this->base = shared_base; + } + this->http.reset(evhttp_new(this->base.get()), evhttp_free); evhttp_set_gencb(this->http.get(), this->dispatch_handle_request, this); + if (!shared_base) { + this->th = thread(&HTTPServer::thread_fn, this); + } } void HTTPServer::listen(const string& socket_path) { diff --git a/src/HTTPServer.hh b/src/HTTPServer.hh index 813554b4..a1080f37 100644 --- a/src/HTTPServer.hh +++ b/src/HTTPServer.hh @@ -13,7 +13,8 @@ class HTTPServer { public: - HTTPServer(std::shared_ptr state); + // shared_base should be null unless + HTTPServer(std::shared_ptr state, std::shared_ptr shared_base); HTTPServer(const HTTPServer&) = delete; HTTPServer(HTTPServer&&) = delete; HTTPServer& operator=(const HTTPServer&) = delete; @@ -57,7 +58,7 @@ protected: std::shared_ptr state; std::shared_ptr base; std::shared_ptr http; - std::thread th; + std::thread th; // Not used on Windows std::unordered_set> rare_drop_subscribers; diff --git a/src/Main.cc b/src/Main.cc index 334d6d56..dd962837 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -3114,7 +3114,8 @@ Action a_run_server_replay_log( if (!state->http_addresses.empty() || !state->http_addresses.empty()) { config_log.info("Starting HTTP server"); - state->http_server = make_shared(state); + shared_ptr shared_base = IS_WINDOWS ? state->base : nullptr; + state->http_server = make_shared(state, shared_base); for (const auto& it : state->http_addresses) { auto netloc = phosg::parse_netloc(it); state->http_server->listen(netloc.first, netloc.second);