1
0
mirror of synced 2025-04-20 11:47:43 +03:00

Added SIGINT signal handler.

This commit is contained in:
yhirose 2012-09-26 11:55:14 -04:00
parent 95c0a6d7a8
commit 6818f18275

View File

@ -7,14 +7,23 @@
#include <httpsvrkit.h>
#include <cstdio>
#include <signal.h>
using namespace httpsvrkit;
template<typename Fn> void signal(int sig, Fn fn)
{
static std::function<void ()> signal_handler_;
struct SignalHandler { static void fn(int sig) { signal_handler_(); } };
signal_handler_ = fn;
signal(sig, SignalHandler::fn);
}
int main(void)
{
const char* hi = "/hi";
HTTP_SERVER("localhost", 1234) {
// svr, req, res
GET("/", {
res.set_redirect(hi);
@ -27,6 +36,10 @@ int main(void)
GET("/dump", {
res.set_content(dump_request(cxt));
});
signal(SIGINT, [&](){
svr->stop();
});
}
}