summaryrefslogtreecommitdiff
path: root/src/server/client.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/client.zig')
-rw-r--r--src/server/client.zig115
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");
+ // };
+ // }
////////