diff options
| author | Robby Zambito <contact@robbyzambito.me> | 2026-01-02 15:19:19 +0000 |
|---|---|---|
| committer | Robby Zambito <contact@robbyzambito.me> | 2026-01-02 15:29:58 +0000 |
| commit | 2be370e379959e2763e70851cf14ecfca07754fc (patch) | |
| tree | 54412e021efef581490ebc985ca5b161f1faeee0 /src/server/client.zig | |
| parent | 539255adb1f0a681ff49ebfb9e1e3c7198ad5310 (diff) | |
Support subject patterns
clean up some tests
Diffstat (limited to 'src/server/client.zig')
| -rw-r--r-- | src/server/client.zig | 115 |
1 files changed, 44 insertions, 71 deletions
diff --git a/src/server/client.zig b/src/server/client.zig index 5db6ff1..23a0c9d 100644 --- a/src/server/client.zig +++ b/src/server/client.zig @@ -112,28 +112,17 @@ test { { // Simulate stream while (Message.next(gpa, &from_client)) |msg| { - switch (msg) { - .eos => { - try from_client_queue.putOne(io, msg); - break; - }, - else => { - try from_client_queue.putOne(io, msg); - }, - } + try from_client_queue.putOne(io, msg); } else |err| switch (err) { - error.EndOfStream => try from_client_queue.close(io), + error.EndOfStream => from_client_queue.close(io), else => return err, } while (from_client_queue.getOne(io)) |msg| { switch (msg) { - .eos => { - break; - }, .connect => |*c| { std.debug.print("Message: {any}\n", .{msg}); - c.deinit(); + c.deinit(gpa); }, else => { std.debug.print("Message: {any}\n", .{msg}); @@ -146,63 +135,47 @@ test { // Reset the reader to process it again. from_client.seek = 0; - { - const SemiClient = struct { - q: std.Io.Queue(Message), - - fn parseClientInput(self: *@This(), ioh: std.Io, in: *std.Io.Reader) void { - defer std.debug.print("done parse\n", .{}); - while (Message.next(gpa, in)) |msg| { - switch (msg) { - .eos => { - self.q.putOne(ioh, msg) catch return; - break; - }, - else => { - self.q.putOne(ioh, msg) catch return; - }, - } - } else |_| {} - } - - fn next(self: *@This(), ioh: std.Io) !Message { - return self.q.getOne(ioh); - } - - fn printAll(self: *@This(), ioh: std.Io) void { - defer std.debug.print("done print\n", .{}); - while (self.next(ioh)) |*msg| { - switch (msg.*) { - .eos => |_| { - break; - }, - else => {}, - } - std.debug.print("Client msg: {any}\n", .{msg}); - switch (msg.*) { - .connect => |c| { - // c.allocator.deinit(); - c.deinit(); - // @constCast(c).deinit(); - }, - else => {}, - } - } else |_| {} - } - }; - - var c: SemiClient = .{ .q = from_client_queue }; - var group: std.Io.Group = .init; - defer group.wait(io); - - group.concurrent(io, SemiClient.printAll, .{ &c, io }) catch { - @panic("could not start printAll\n"); - }; - - group.concurrent(io, SemiClient.parseClientInput, .{ &c, io, &from_client }) catch { - @panic("could not start printAll\n"); - }; - } + // { + // const SemiClient = struct { + // q: std.Io.Queue(Message), + + // fn parseClientInput(self: *@This(), ioh: std.Io, in: *std.Io.Reader) void { + // defer std.debug.print("done parse\n", .{}); + // while (Message.next(gpa, in)) |msg| { + // self.q.putOne(ioh, msg) catch return; + // } else |_| {} + // } + + // fn next(self: *@This(), ioh: std.Io) !Message { + // return self.q.getOne(ioh); + // } + + // fn printAll(self: *@This(), ioh: std.Io) void { + // defer std.debug.print("done print\n", .{}); + // while (self.next(ioh)) |*msg| { + // std.debug.print("Client msg: {any}\n", .{msg}); + // switch (msg.*) { + // .connect => |c| { + // c.deinit(gpa); + // }, + // else => {}, + // } + // } else |_| {} + // } + // }; + + // var c: SemiClient = .{ .q = from_client_queue }; + // var group: std.Io.Group = .init; + // defer group.wait(io); + + // group.concurrent(io, SemiClient.printAll, .{ &c, io }) catch { + // @panic("could not start printAll\n"); + // }; + + // group.concurrent(io, SemiClient.parseClientInput, .{ &c, io, &from_client }) catch { + // @panic("could not start printAll\n"); + // }; + // } //////// |
