add signal handlers

This commit is contained in:
SuspiciousActivity committed 2026-10-03 17:18:30 +02:00
1 parent da8a4903a7
commit c2d4e01d0b
2 files changed
+9 -1

No files matched your search

+8
View File
@@ -3,6 +3,9 @@
#include <string>
#include <iostream>
#include <sstream>
#include <csignal>
httplib::Server *g_svr = nullptr;
std::string stripLabel(const std::string &label) {
const std::string prefix = "__label__";
@@ -59,8 +62,13 @@ int main(int argc, char *argv[]) {
res.set_content(result, "application/json");
});
g_svr = &svr;
std::signal(SIGINT, [](int) { if (g_svr) g_svr->stop(); });
std::signal(SIGTERM, [](int) { if (g_svr) g_svr->stop(); });
auto port = std::stoi(argv[2]);
std::cout << "Starting server on port " << port << std::endl;
svr.listen("0.0.0.0", port);
std::cout << "Server stopped" << std::endl;
return 0;
}