mirror of
https://git.robbyzambito.me/zits
synced 2026-02-04 03:34: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;
|
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;
|
self.recv_queue = queue;
|
||||||
var msgs: [8]Message = undefined;
|
var msgs: [8]Message = undefined;
|
||||||
|
|
||||||
// Do initial handshake with client
|
|
||||||
try queue.putOne(io, .{ .info = server_info });
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const len = try queue.get(io, &msgs, 1);
|
const len = try queue.get(io, &msgs, 1);
|
||||||
std.debug.assert(len <= msgs.len);
|
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 {};
|
defer server_task.cancel(io) catch {};
|
||||||
|
|
||||||
while (keep_running.load(.monotonic)) {
|
while (keep_running.load(.monotonic)) {
|
||||||
try io.sleep(.fromMilliseconds(10), .awake);
|
try io.sleep(.fromMilliseconds(1), .awake);
|
||||||
}
|
}
|
||||||
|
|
||||||
std.debug.print("\n", .{});
|
std.debug.print("\n", .{});
|
||||||
@@ -179,7 +179,10 @@ fn handleConnection(
|
|||||||
} else |_| {}
|
} 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 {};
|
defer client_task.cancel(io) catch {};
|
||||||
|
|
||||||
// Messages are owned by the server after they are received from the client
|
// Messages are owned by the server after they are received from the client
|
||||||
|
|||||||
Reference in New Issue
Block a user