run the HTTP server on the event thread on Windows
This commit is contained in:
+11
-5
@@ -162,12 +162,18 @@ const string& HTTPServer::get_url_param(
|
|||||||
return range.first->second;
|
return range.first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPServer::HTTPServer(shared_ptr<ServerState> state)
|
HTTPServer::HTTPServer(shared_ptr<ServerState> state, shared_ptr<struct event_base> shared_base)
|
||||||
: state(state),
|
: state(state) {
|
||||||
base(event_base_new(), event_base_free),
|
if (!shared_base) {
|
||||||
http(evhttp_new(this->base.get()), evhttp_free),
|
this->base.reset(event_base_new(), event_base_free);
|
||||||
th(&HTTPServer::thread_fn, this) {
|
} 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);
|
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) {
|
void HTTPServer::listen(const string& socket_path) {
|
||||||
|
|||||||
+3
-2
@@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
class HTTPServer {
|
class HTTPServer {
|
||||||
public:
|
public:
|
||||||
HTTPServer(std::shared_ptr<ServerState> state);
|
// shared_base should be null unless
|
||||||
|
HTTPServer(std::shared_ptr<ServerState> state, std::shared_ptr<struct event_base> shared_base);
|
||||||
HTTPServer(const HTTPServer&) = delete;
|
HTTPServer(const HTTPServer&) = delete;
|
||||||
HTTPServer(HTTPServer&&) = delete;
|
HTTPServer(HTTPServer&&) = delete;
|
||||||
HTTPServer& operator=(const HTTPServer&) = delete;
|
HTTPServer& operator=(const HTTPServer&) = delete;
|
||||||
@@ -57,7 +58,7 @@ protected:
|
|||||||
std::shared_ptr<ServerState> state;
|
std::shared_ptr<ServerState> state;
|
||||||
std::shared_ptr<struct event_base> base;
|
std::shared_ptr<struct event_base> base;
|
||||||
std::shared_ptr<struct evhttp> http;
|
std::shared_ptr<struct evhttp> http;
|
||||||
std::thread th;
|
std::thread th; // Not used on Windows
|
||||||
|
|
||||||
std::unordered_set<std::shared_ptr<WebsocketClient>> rare_drop_subscribers;
|
std::unordered_set<std::shared_ptr<WebsocketClient>> rare_drop_subscribers;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -3114,7 +3114,8 @@ Action a_run_server_replay_log(
|
|||||||
|
|
||||||
if (!state->http_addresses.empty() || !state->http_addresses.empty()) {
|
if (!state->http_addresses.empty() || !state->http_addresses.empty()) {
|
||||||
config_log.info("Starting HTTP server");
|
config_log.info("Starting HTTP server");
|
||||||
state->http_server = make_shared<HTTPServer>(state);
|
shared_ptr<struct event_base> shared_base = IS_WINDOWS ? state->base : nullptr;
|
||||||
|
state->http_server = make_shared<HTTPServer>(state, shared_base);
|
||||||
for (const auto& it : state->http_addresses) {
|
for (const auto& it : state->http_addresses) {
|
||||||
auto netloc = phosg::parse_netloc(it);
|
auto netloc = phosg::parse_netloc(it);
|
||||||
state->http_server->listen(netloc.first, netloc.second);
|
state->http_server->listen(netloc.first, netloc.second);
|
||||||
|
|||||||
Reference in New Issue
Block a user