Move handshake from client to server

This commit is contained in:
2026-01-02 22:36:41 +00:00
parent 29e5b92ee0
commit 67908cf198
2 changed files with 6 additions and 6 deletions

View File

@@ -30,13 +30,10 @@ pub fn deinit(self: *Client, alloc: std.mem.Allocator) void {
self.* = undefined;
}
pub fn start(self: *Client, io: std.Io, alloc: std.mem.Allocator, queue: *std.Io.Queue(Message), server_info: Message.ServerInfo) !void {
pub fn start(self: *Client, io: std.Io, alloc: std.mem.Allocator, queue: *std.Io.Queue(Message)) !void {
self.recv_queue = queue;
var msgs: [8]Message = undefined;
// Do initial handshake with client
try queue.putOne(io, .{ .info = server_info });
while (true) {
const len = try queue.get(io, &msgs, 1);
std.debug.assert(len <= msgs.len);

View File

@@ -67,7 +67,7 @@ pub fn main(alloc: std.mem.Allocator, server_config: ServerInfo) !void {
defer server_task.cancel(io) catch {};
while (keep_running.load(.monotonic)) {
try io.sleep(.fromMilliseconds(10), .awake);
try io.sleep(.fromMilliseconds(1), .awake);
}
std.debug.print("\n", .{});
@@ -179,7 +179,10 @@ fn handleConnection(
} else |_| {}
}
var client_task = try io.concurrent(Client.start, .{ &client, io, server_allocator, &queue, server.info });
// Do initial handshake with client
try queue.putOne(io, .{ .info = server.info });
var client_task = try io.concurrent(Client.start, .{ &client, io, server_allocator, &queue });
defer client_task.cancel(io) catch {};
// Messages are owned by the server after they are received from the client