aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-16 00:49:43 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-16 00:52:32 +0800
commitf299c93242c1543602a3a7abc5af73f7c46f680e (patch)
treecd7ea76ebdc811029ccc0ec3fcef68527edd5e73
parentClose the static_fs (diff)
downloadforge-f299c93242c1543602a3a7abc5af73f7c46f680e.tar.gz
forge-f299c93242c1543602a3a7abc5af73f7c46f680e.tar.zst
forge-f299c93242c1543602a3a7abc5af73f7c46f680e.zip
Handle SIGINT
-rw-r--r--main.ha11
1 files changed, 10 insertions, 1 deletions
diff --git a/main.ha b/main.ha
index cf2099a..d133c7b 100644
--- a/main.ha
+++ b/main.ha
@@ -16,6 +16,7 @@ use memio;
use io;
use fmt;
use bufio;
+use unix::signal;
const usage: [_]getopt::help = [
"Lindenii Forge Server",
@@ -24,7 +25,15 @@ const usage: [_]getopt::help = [
let static_fs: nullable *fs::fs = null;
+let running: bool = true;
+
+export fn sigint_handler(sig: signal::sig, info: *signal::siginfo, ucontext: *opaque) void = {
+ running = false;
+};
+
export fn main() void = {
+ signal::handle(signal::sig::INT, &sigint_handler, signal::flag::NONE, null);
+
const cmd = getopt::parse(os::args, usage...);
defer getopt::finish(&cmd);
@@ -48,7 +57,7 @@ export fn main() void = {
};
defer http::server_finish(server);
- for (true) {
+ for (running) {
const serv_req = match (http::serve(server)) {
case let this: *http::server_request =>
yield this;