From e2a60c9427bfaf63149b4692459e86749553f755 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Tue, 6 Jan 2026 23:10:33 -0500 Subject: Rename to match actual subcommand --- src/main.zig | 4 +-- src/subcommand/serve.zig | 65 +++++++++++++++++++++++++++++++++++++++++++++++ src/subcommand/server.zig | 65 ----------------------------------------------- 3 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 src/subcommand/serve.zig delete mode 100644 src/subcommand/server.zig diff --git a/src/main.zig b/src/main.zig index 7784df8..79de5e7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,7 +6,7 @@ const yazap = @import("yazap"); const Message = zits.MessageParser.Message; const Server = zits.Server; -const serverSubcommand = @import("./subcommand/server.zig").main; +const serve = @import("./subcommand/serve.zig").main; pub fn main() !void { var dba: std.heap.DebugAllocator(.{}) = .init; @@ -69,7 +69,7 @@ pub fn main() !void { info.server_name = name; } - try serverSubcommand(gpa, info); + try serve(gpa, info); return; } else if (matches.subcommandMatches("pub")) |_| { std.debug.print("Unimplemented\n", .{}); diff --git a/src/subcommand/serve.zig b/src/subcommand/serve.zig new file mode 100644 index 0000000..54258a9 --- /dev/null +++ b/src/subcommand/serve.zig @@ -0,0 +1,65 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const DebugAllocator = std.heap.DebugAllocator; +const Sigaction = std.posix.Sigaction; + +const Io = std.Io; +const Threaded = Io.Threaded; + +const builtin = @import("builtin"); + +const zits = @import("zits"); +const Message = zits.Server.parse.Message; +const ServerInfo = Message.ServerInfo; + +const Server = zits.Server; + +const safe_build = builtin.mode == .Debug or builtin.mode == .ReleaseSafe; + +var exit_lock: std.Io.Mutex = .init; +var io: Io = undefined; + +fn handleSigInt(sig: std.os.linux.SIG) callconv(.c) void { + _ = sig; + exit_lock.unlock(io); +} + +pub fn main(outer_alloc: Allocator, server_config: ServerInfo) !void { + { + var dba: DebugAllocator(.{}) = .init; + dba.backing_allocator = outer_alloc; + defer _ = dba.deinit(); + const alloc = if (safe_build) dba.allocator() else outer_alloc; + + var threaded: Threaded = .init(alloc, .{}); + defer threaded.deinit(); + io = threaded.io(); + + try exit_lock.lock(io); + + // Configure the signal action + const act = Sigaction{ + .handler = .{ .handler = handleSigInt }, + .mask = std.posix.sigemptyset(), + .flags = 0, + }; + + // Register the handler for SIGINT (Ctrl+C) + std.posix.sigaction(std.posix.SIG.INT, &act, null); + + var server: Server = .{ + .info = server_config, + }; + defer server.deinit(io, alloc); + + var server_task = try io.concurrent(Server.start, .{ &server, io, alloc }); + defer server_task.cancel(io) catch {}; + + // Block until Ctrl+C + try exit_lock.lock(io); + std.debug.print("\n", .{}); + std.log.info("Shutting down...", .{}); + server_task.cancel(io) catch {}; + } + std.log.info("Goodbye", .{}); +} diff --git a/src/subcommand/server.zig b/src/subcommand/server.zig deleted file mode 100644 index 54258a9..0000000 --- a/src/subcommand/server.zig +++ /dev/null @@ -1,65 +0,0 @@ -const std = @import("std"); -const Allocator = std.mem.Allocator; -const DebugAllocator = std.heap.DebugAllocator; -const Sigaction = std.posix.Sigaction; - -const Io = std.Io; -const Threaded = Io.Threaded; - -const builtin = @import("builtin"); - -const zits = @import("zits"); -const Message = zits.Server.parse.Message; -const ServerInfo = Message.ServerInfo; - -const Server = zits.Server; - -const safe_build = builtin.mode == .Debug or builtin.mode == .ReleaseSafe; - -var exit_lock: std.Io.Mutex = .init; -var io: Io = undefined; - -fn handleSigInt(sig: std.os.linux.SIG) callconv(.c) void { - _ = sig; - exit_lock.unlock(io); -} - -pub fn main(outer_alloc: Allocator, server_config: ServerInfo) !void { - { - var dba: DebugAllocator(.{}) = .init; - dba.backing_allocator = outer_alloc; - defer _ = dba.deinit(); - const alloc = if (safe_build) dba.allocator() else outer_alloc; - - var threaded: Threaded = .init(alloc, .{}); - defer threaded.deinit(); - io = threaded.io(); - - try exit_lock.lock(io); - - // Configure the signal action - const act = Sigaction{ - .handler = .{ .handler = handleSigInt }, - .mask = std.posix.sigemptyset(), - .flags = 0, - }; - - // Register the handler for SIGINT (Ctrl+C) - std.posix.sigaction(std.posix.SIG.INT, &act, null); - - var server: Server = .{ - .info = server_config, - }; - defer server.deinit(io, alloc); - - var server_task = try io.concurrent(Server.start, .{ &server, io, alloc }); - defer server_task.cancel(io) catch {}; - - // Block until Ctrl+C - try exit_lock.lock(io); - std.debug.print("\n", .{}); - std.log.info("Shutting down...", .{}); - server_task.cancel(io) catch {}; - } - std.log.info("Goodbye", .{}); -} -- cgit