Chunk messages to 1000 byte payloads

This commit is contained in:
2026-01-24 10:55:29 -05:00
parent 157afa13b1
commit fc9c5bcd5d
3 changed files with 17 additions and 6 deletions

View File

@@ -5,6 +5,8 @@ const Client = @This();
const max_message_size = 2048;
pub const max_payload_len = RawSocket.max_payload_len;
socket: RawSocket,
pub fn init() !Client {

View File

@@ -4,6 +4,8 @@ fd: i32,
sockaddr_ll: std.posix.sockaddr.ll,
mac: [6]u8,
pub const max_payload_len = 1000;
const Ifconf = extern struct {
ifc_len: i32,
ifc_ifcu: extern union {

View File

@@ -127,17 +127,24 @@ pub fn main(init: std.process.Init) !void {
var child_stderr: std.ArrayList(u8) = .empty;
defer child_stderr.deinit(init.gpa);
try child.collectOutput(init.gpa, &child_stdout, &child_stderr, 2048);
try child.collectOutput(init.gpa, &child_stdout, &child_stderr, std.math.maxInt(usize));
const b64e = std.base64.standard.Encoder;
// const b64e = std.base64.standard.Encoder;
var cmd_output: Writer = blk: {
var cmd_output_buf: [2048]u8 = undefined;
const encoded_cmd_output = b64e.encode(&cmd_output_buf, child_stdout.items);
break :blk .fixed(&cmd_output_buf);
};
connection.send(init.io, encoded_cmd_output) catch continue;
var cmd_output_window_iter = std.mem.window(u8, child_stdout.items, SaprusClient.max_payload_len, SaprusClient.max_payload_len);
while (cmd_output_window_iter.next()) |chunk| {
cmd_output.end = 0;
try cmd_output.print("{b64}", .{chunk});
try connection.send(init.io, cmd_output.buffered());
try init.io.sleep(.fromMilliseconds(40), .real);
}
}
}
}
unreachable;
}