support hpub

fixed issue where not all data was being sent
request reply has a performance issue but technically works
This commit is contained in:
2026-01-08 11:48:12 -05:00
parent 45feccbad8
commit d8488fde49
3 changed files with 186 additions and 859 deletions

View File

@@ -6,11 +6,6 @@ const Queue = std.Io.Queue;
const Client = @This();
pub const Msgs = union(enum) {
MSG: Message.Msg,
HMSG: Message.HMsg,
};
connect: ?Message.Connect,
// Byte queue for this client to receive.
recv_queue: *Queue(u8),
@@ -48,69 +43,6 @@ pub fn start(self: *Client, io: std.Io) !void {
self.to_client.end = try self.recv_queue.get(io, self.to_client.buffer, 1);
try self.to_client.flush();
}
// while (true) {
// switch (try io.select(.{ .msgs = &recv_msgs_task, .proto = &recv_proto_task })) {
// .msgs => |len_err| {
// @branchHint(.likely);
// const msgs = msgs_buf[0..try len_err];
// for (0..msgs.len) |i| {
// const msg = msgs[i];
// defer switch (msg) {
// .MSG => |m| m.deinit(self.alloc),
// .HMSG => |h| h.deinit(self.alloc),
// };
// errdefer for (msgs[i + 1 ..]) |mg| switch (mg) {
// .MSG => |m| {
// m.deinit(self.alloc);
// },
// .HMSG => |h| {
// h.deinit(self.alloc);
// },
// };
// switch (msg) {
// .MSG => |m| {
// },
// .HMSG => |hmsg| {
// try self.to_client.print("HMSG {s} {s} {s} {d} {d}\r\n", .{
// hmsg.msg.subject,
// hmsg.msg.sid,
// hmsg.msg.reply_to orelse "",
// hmsg.header_bytes,
// hmsg.msg.payload.len,
// });
// try hmsg.msg.payload.write(self.to_client);
// try self.to_client.print("\r\n", .{});
// },
// }
// }
// recv_msgs_task = io.concurrent(Queue(Msgs).get, .{ self.msg_queue, io, &msgs_buf, 1 }) catch unreachable;
// },
// .proto => |msg_err| {
// @branchHint(.unlikely);
// const msg = try msg_err;
// switch (msg) {
// .@"+OK" => {
// _ = try self.to_client.write("+OK\r\n");
// },
// .PONG => {
// _ = try self.to_client.write("PONG\r\n");
// },
// .INFO => |info| {
// },
// .@"-ERR" => |s| {
// _ = try self.to_client.print("-ERR '{s}'\r\n", .{s});
// },
// else => |m| {
// std.debug.panic("unimplemented write: {any}\n", .{m});
// },
// }
// recv_proto_task = io.concurrent(Queue(Message).getOne, .{ self.recv_queue, io }) catch unreachable;
// },
// }
// try self.to_client.flush();
// }
}
pub fn send(self: *Client, io: std.Io, msg: []const u8) !void {