summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/main.zig15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/server/main.zig b/src/server/main.zig
index f3728ea..044f551 100644
--- a/src/server/main.zig
+++ b/src/server/main.zig
@@ -83,6 +83,9 @@ pub fn start(server: *Server, io: std.Io, gpa: std.mem.Allocator) !void {
), io, .{ .reuse_address = true });
defer tcp_server.deinit(io);
+ var client_group: std.Io.Group = .init;
+ defer client_group.cancel(io);
+
var id: usize = 0;
// Run until SIGINT is handled, then exit gracefully
while (true) : (id +%= 1) {
@@ -90,7 +93,7 @@ pub fn start(server: *Server, io: std.Io, gpa: std.mem.Allocator) !void {
if (server.clients.contains(id)) continue;
const stream = try tcp_server.accept(io);
std.debug.print("accepted connection\n", .{});
- _ = io.concurrent(handleConnection, .{ server, gpa, io, id, stream }) catch {
+ _ = client_group.concurrent(io, handleConnectionInfallible, .{ server, gpa, io, id, stream }) catch {
std.debug.print("could not start concurrent handler for {d}\n", .{id});
stream.close(io);
};
@@ -118,6 +121,16 @@ fn removeClient(server: *Server, io: std.Io, allocator: std.mem.Allocator, id: u
}
}
+fn handleConnectionInfallible(
+ server: *Server,
+ server_allocator: std.mem.Allocator,
+ io: std.Io,
+ id: usize,
+ stream: std.Io.net.Stream,
+) void {
+ handleConnection(server, server_allocator, io, id, stream) catch {};
+}
+
fn handleConnection(
server: *Server,
server_allocator: std.mem.Allocator,