added signal handler
This commit is contained in:
parent
722357388c
commit
122b4998d6
@ -70,8 +70,16 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
|
|
||||||
event_system::instance().start();
|
event_system::instance().start();
|
||||||
|
|
||||||
static auto *this_server{server_};
|
static std::atomic<httplib::Server *> this_server{server_};
|
||||||
static const auto quit_handler = [](int /* sig */) { this_server->stop(); };
|
static const auto quit_handler = [](int /* sig */) {
|
||||||
|
auto *ptr = this_server.load();
|
||||||
|
if (ptr == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this_server = nullptr;
|
||||||
|
ptr->stop();
|
||||||
|
};
|
||||||
|
|
||||||
std::signal(SIGINT, quit_handler);
|
std::signal(SIGINT, quit_handler);
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
@ -80,6 +88,7 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
std::signal(SIGTERM, quit_handler);
|
std::signal(SIGTERM, quit_handler);
|
||||||
|
|
||||||
server_->listen("127.0.0.1", config_->get_api_port());
|
server_->listen("127.0.0.1", config_->get_api_port());
|
||||||
|
this_server = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
handlers::~handlers() { event_system::instance().stop(); }
|
handlers::~handlers() { event_system::instance().stop(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user