|
@@ -7,14 +7,23 @@
|
|
|
|
|
|
|
|
#include <httpsvrkit.h>
|
|
#include <httpsvrkit.h>
|
|
|
#include <cstdio>
|
|
#include <cstdio>
|
|
|
|
|
+#include <signal.h>
|
|
|
|
|
|
|
|
using namespace httpsvrkit;
|
|
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)
|
|
int main(void)
|
|
|
{
|
|
{
|
|
|
const char* hi = "/hi";
|
|
const char* hi = "/hi";
|
|
|
-
|
|
|
|
|
HTTP_SERVER("localhost", 1234) {
|
|
HTTP_SERVER("localhost", 1234) {
|
|
|
|
|
+ // svr, req, res
|
|
|
|
|
|
|
|
GET("/", {
|
|
GET("/", {
|
|
|
res.set_redirect(hi);
|
|
res.set_redirect(hi);
|
|
@@ -27,6 +36,10 @@ int main(void)
|
|
|
GET("/dump", {
|
|
GET("/dump", {
|
|
|
res.set_content(dump_request(cxt));
|
|
res.set_content(dump_request(cxt));
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ signal(SIGINT, [&](){
|
|
|
|
|
+ svr->stop();
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|