cdp: send I/O next read before executing current cmd

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-21 18:21:43 +02:00
parent f30501ca3c
commit 20dd140c31
2 changed files with 90 additions and 91 deletions

View File

@@ -128,17 +128,6 @@ pub const Ctx = struct {
return;
}
// input
const input = self.read_buf[0..size];
// read and execute input
self.msg_buf.read(self.alloc(), input, self, Ctx.do) catch |err| {
if (err != error.Closed) {
log.err("do error: {any}", .{err});
}
return;
};
// set connection timestamp
self.last_active = std.time.Instant.now() catch |err| {
log.err("read timestamp error: {any}", .{err});
@@ -154,6 +143,26 @@ pub const Ctx = struct {
self.conn_socket,
self.read_buf,
);
// read and execute input
var input: []const u8 = self.read_buf[0..size];
while (input.len > 0) {
const parts = self.msg_buf.read(self.alloc(), input) catch |err| {
if (err == error.MsgMultipart) {
return;
} else {
log.err("msg read error: {any}", .{err});
return;
}
};
input = parts.left;
// execute
self.do(parts.msg) catch |err| {
if (err != error.Closed) {
log.err("do error: {any}", .{err});
}
};
}
}
fn timeoutCbk(self: *Ctx, completion: *Completion, result: TimeoutError!void) void {