diff options
Diffstat (limited to 'main.ha')
-rw-r--r-- | main.ha | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> // Adapted from template by Willow Barraco <contact@willowbarraco.fr> +use fs; use getopt; use log; use net; @@ -15,13 +16,24 @@ use memio; use io; use fmt; use bufio; +use unix::signal; const usage: [_]getopt::help = [ "Lindenii Forge Server", ('c', "config", "path to configuration file") ]; +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); @@ -31,10 +43,13 @@ export fn main() void = { for (let opt .. cmd.opts) { switch (opt.0) { case 'c' => yield; // TODO: actually handle the config - case => abort(); // unreachable + case => abort("unreachable"); }; }; + static_fs = os::diropen("static")!; + defer fs::close(static_fs as *fs::fs); + const server = match (http::listen(ip_addr, port, net::tcp::reuseport, net::tcp::reuseaddr)) { case let this: *http::server => yield this; @@ -42,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; |