diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-16 00:49:43 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-16 00:52:32 +0800 |
commit | f299c93242c1543602a3a7abc5af73f7c46f680e (patch) | |
tree | cd7ea76ebdc811029ccc0ec3fcef68527edd5e73 /main.ha | |
parent | Close the static_fs (diff) | |
download | forge-f299c93242c1543602a3a7abc5af73f7c46f680e.tar.gz forge-f299c93242c1543602a3a7abc5af73f7c46f680e.tar.zst forge-f299c93242c1543602a3a7abc5af73f7c46f680e.zip |
Handle SIGINT
Diffstat (limited to 'main.ha')
-rw-r--r-- | main.ha | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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; |