mirror of
https://git.robbyzambito.me/zaprus/
synced 2026-02-04 11:44:49 +00:00
Chunk messages to 1000 byte payloads
This commit is contained in:
19
src/main.zig
19
src/main.zig
@@ -127,14 +127,21 @@ 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;
|
||||
var cmd_output_buf: [2048]u8 = undefined;
|
||||
const encoded_cmd_output = b64e.encode(&cmd_output_buf, child_stdout.items);
|
||||
// const b64e = std.base64.standard.Encoder;
|
||||
var cmd_output: Writer = blk: {
|
||||
var cmd_output_buf: [2048]u8 = undefined;
|
||||
break :blk .fixed(&cmd_output_buf);
|
||||
};
|
||||
|
||||
connection.send(init.io, encoded_cmd_output) catch continue;
|
||||
try init.io.sleep(.fromMilliseconds(40), .real);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user