mirror of
https://git.robbyzambito.me/zits
synced 2026-02-04 11:44:48 +00:00
97 mbps !!! super fast
dosen't flush every message, pulls batches from the queue to send, and flushes at the end of each batch. batches are a min of 1 message, but may be more.
This commit is contained in:
@@ -25,7 +25,7 @@ pub fn init(
|
||||
|
||||
pub fn start(self: *Client, io: std.Io, alloc: std.mem.Allocator, queue: *std.Io.Queue(Message)) !void {
|
||||
self.recv_queue = queue;
|
||||
var msgs: [16]Message = undefined;
|
||||
var msgs: [8]Message = undefined;
|
||||
while (true) {
|
||||
const len = try queue.get(io, &msgs, 1);
|
||||
std.debug.assert(len <= msgs.len);
|
||||
@@ -49,6 +49,7 @@ pub fn start(self: *Client, io: std.Io, alloc: std.mem.Allocator, queue: *std.Io
|
||||
},
|
||||
}
|
||||
}
|
||||
try self.to_client.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,19 +69,20 @@ pub fn next(self: *Client, allocator: std.mem.Allocator) !Message {
|
||||
|
||||
fn writeOk(out: *std.Io.Writer) !void {
|
||||
_ = try out.write("+OK\r\n");
|
||||
try out.flush();
|
||||
}
|
||||
|
||||
fn writeErr(out: *std.Io.Writer, msg: []const u8) !void {
|
||||
_ = try out.print("-ERR '{s}'\r\n", .{msg});
|
||||
}
|
||||
|
||||
fn writePong(out: *std.Io.Writer) !void {
|
||||
_ = try out.write("PONG\r\n");
|
||||
try out.flush();
|
||||
}
|
||||
|
||||
pub fn writeInfo(out: *std.Io.Writer, info: Message.ServerInfo) !void {
|
||||
_ = try out.write("INFO ");
|
||||
try std.json.Stringify.value(info, .{}, out);
|
||||
_ = try out.write("\r\n");
|
||||
try out.flush();
|
||||
}
|
||||
|
||||
fn writeMsg(out: *std.Io.Writer, msg: Message.Msg) !void {
|
||||
@@ -94,7 +96,6 @@ fn writeMsg(out: *std.Io.Writer, msg: Message.Msg) !void {
|
||||
msg.payload,
|
||||
},
|
||||
);
|
||||
try out.flush();
|
||||
}
|
||||
|
||||
test {
|
||||
|
||||
Reference in New Issue
Block a user