diff options
| author | Robby Zambito <contact@robbyzambito.me> | 2026-01-01 03:08:56 +0000 |
|---|---|---|
| committer | Robby Zambito <contact@robbyzambito.me> | 2026-01-01 05:22:03 +0000 |
| commit | f289ab78934dd527f24517748e0441f0aea1d42d (patch) | |
| tree | b2b49e85ab1aaeff8a59f2eeda5e7990feb95a54 /src/server/main.zig | |
| parent | 4fcb9e3943b899b01bbb959dcf322af1855abf69 (diff) | |
Rename ClientState to Client
Diffstat (limited to 'src/server/main.zig')
| -rw-r--r-- | src/server/main.zig | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/server/main.zig b/src/server/main.zig index 4f52bec..4d62e93 100644 --- a/src/server/main.zig +++ b/src/server/main.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Message = @import("./message_parser.zig").Message; pub const ServerInfo = Message.ServerInfo; -const ClientState = @import("./client.zig").ClientState; +const Client = @import("./client.zig"); const Server = @This(); const Subscription = struct { @@ -12,7 +12,7 @@ const Subscription = struct { }; info: ServerInfo, -clients: std.AutoHashMapUnmanaged(usize, *ClientState) = .empty, +clients: std.AutoHashMapUnmanaged(usize, *Client) = .empty, subs_lock: std.Io.Mutex = .init, subscriptions: std.ArrayList(Subscription) = .empty, @@ -43,7 +43,6 @@ pub fn main(gpa: std.mem.Allocator, server_config: ServerInfo) !void { defer threaded.deinit(); const io = threaded.io(); - var tcp_server = try std.Io.net.IpAddress.listen(try std.Io.net.IpAddress.parse( server.info.host, server.info.port, @@ -88,7 +87,7 @@ fn processMsgs(server: *Server, io: std.Io, alloc: std.mem.Allocator) void { } } -fn addClient(server: *Server, allocator: std.mem.Allocator, id: usize, client: *ClientState) !void { +fn addClient(server: *Server, allocator: std.mem.Allocator, id: usize, client: *Client) !void { // server.clients.lockPointers(); try server.clients.put(allocator, id, client); // server.clients.unlockPointers(); @@ -132,25 +131,25 @@ fn handleConnection( var reader = stream.reader(io, r_buffer); const in = &reader.interface; - var client_state: ClientState = .init(null, in, out); - try client_state.send(io, .{ .info = server.info }); + var client: Client = .init(null, in, out); + try client.send(io, .{ .info = server.info }); var connect_arena: std.heap.ArenaAllocator = .init(allocator); defer connect_arena.deinit(); - client_state.connect = (Message.next(connect_arena.allocator(), in) catch return).connect; + client.connect = (Message.next(connect_arena.allocator(), in) catch return).connect; - try server.addClient(server_allocator, id, &client_state); + try server.addClient(server_allocator, id, &client); defer server.removeClient(io, server_allocator, id); // Messages are owned by the server after they are received from the client - while (client_state.next(server_allocator)) |msg| { + while (client.next(server_allocator)) |msg| { switch (msg) { .ping => { // Respond to ping with pong. - try client_state.send(io, .pong); + try client.send(io, .pong); }, .@"pub" => |pb| { - _ = io.async(publishMessage, .{ server, io, server_allocator, &client_state, pb }); + _ = io.async(publishMessage, .{ server, io, server_allocator, &client, pb }); }, .sub => |sub| { try server.subscribe(io, server_allocator, id, sub); @@ -181,7 +180,7 @@ fn subjectMatches(expected: []const u8, actual: []const u8) bool { return std.mem.eql(u8, expected, actual); } -fn publishMessage(server: *Server, io: std.Io, gpa: std.mem.Allocator, source_client: *ClientState, msg: Message.Pub) !void { +fn publishMessage(server: *Server, io: std.Io, gpa: std.mem.Allocator, source_client: *Client, msg: Message.Pub) !void { errdefer { if (source_client.connect) |c| { if (c.verbose) { |
