diff --git a/src/http/conn.zig b/src/http/conn.zig index 8975f8b..15a332f 100644 --- a/src/http/conn.zig +++ b/src/http/conn.zig @@ -17,8 +17,21 @@ pub const ConnectionServer = struct { next_conn_id: std.atomic.Atomic(Connection.Id) = std.atomic.Atomic(Connection.Id).init(1), handler: Handler, - // todo accept is a bad name - pub fn accept(self: *ConnectionServer, stream: std.net.Stream, address: std.net.Address) void { + pub fn run(self: *ConnectionServer, addr: std.net.Address) noreturn { + var srv = std.net.StreamServer.init(.{ .reuse_address = true }); + defer srv.deinit(); + + try srv.listen(addr); + + while (true) { + const conn = try srv.accept(); + self.handle(conn.stream, conn.address); + } + + unreachable; + } + + fn handle(self: *ConnectionServer, stream: std.net.Stream, address: std.net.Address) void { const conn = Connection{ .id = self.next_conn_id.fetchAdd(1, .SeqCst), .address = address,