mirror of
https://git.robbyzambito.me/zaprus
synced 2026-02-04 00:14:52 +00:00
Chunk messages to 1000 byte payloads
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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