diff options
Diffstat (limited to 'src/server/Client.zig')
| -rw-r--r-- | src/server/Client.zig | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/server/Client.zig b/src/server/Client.zig index d099ecb..690cabf 100644 --- a/src/server/Client.zig +++ b/src/server/Client.zig @@ -10,6 +10,8 @@ pub const Msgs = union(enum) { }; connect: ?Message.Connect, +// Used to own messages that we receive in our queues. +alloc: std.mem.Allocator, // Messages for this client to receive. recv_queue: *Queue(Message), @@ -20,6 +22,7 @@ to_client: *std.Io.Writer, pub fn init( connect: ?Message.Connect, + alloc: std.mem.Allocator, recv_queue: *Queue(Message), msg_queue: *Queue(Msgs), in: *std.Io.Reader, @@ -27,6 +30,7 @@ pub fn init( ) Client { return .{ .connect = connect, + .alloc = alloc, .recv_queue = recv_queue, .msg_queue = msg_queue, .from_client = in, @@ -41,7 +45,7 @@ pub fn deinit(self: *Client, alloc: std.mem.Allocator) void { self.* = undefined; } -pub fn start(self: *Client, io: std.Io, alloc: std.mem.Allocator) !void { +pub fn start(self: *Client, io: std.Io) !void { var msgs_buf: [1024]Msgs = undefined; var recv_msgs_task = io.concurrent(Queue(Msgs).get, .{ self.msg_queue, io, &msgs_buf, 1 }) catch @panic("Concurrency unavailable"); @@ -58,15 +62,15 @@ pub fn start(self: *Client, io: std.Io, alloc: std.mem.Allocator) !void { for (0..msgs.len) |i| { const msg = msgs[i]; defer switch (msg) { - .MSG => |m| m.deinit(alloc), - .HMSG => |h| h.deinit(alloc), + .MSG => |m| m.deinit(self.alloc), + .HMSG => |h| h.deinit(self.alloc), }; errdefer for (msgs[i + 1 ..]) |mg| switch (mg) { .MSG => |m| { - m.deinit(alloc); + m.deinit(self.alloc); }, .HMSG => |h| { - h.deinit(alloc); + h.deinit(self.alloc); }, }; switch (msg) { |
