mirror of
https://git.robbyzambito.me/zits
synced 2026-02-04 19:54:48 +00:00
Move handshake from client to server
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user