diff --git a/src/main.zig b/src/main.zig index 7c87649..59ea86d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -127,7 +127,11 @@ pub fn main() !void { var auth_header_buf: [256]u8 = undefined; var auth_header = try std.fmt.bufPrint(&auth_header_buf, "Basic {s}", .{auth_encoded}); - const uri = try std.Uri.parse(config.value.loki.url); + var url_buf: [256]u8 = undefined; + @memcpy(url_buf, config.value.loki.url); + var url = url_buf[0..config.value.loki.url]; + + const uri = try std.Uri.parse(url); var client = std.http.Client{ .allocator = allocator }; defer client.deinit(); @@ -140,12 +144,22 @@ pub fn main() !void { port = try std.fmt.bufPrint(&port_buf, "{d}", .{5201}); } + var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var path: []u8 = undefined; + if (config.value.iperf3.path) |p| { + @memcpy(path_buf, p); + path = path_buf[0..p.len]; + } else { + @memcpy(path_buf, "iperf3"); + path = path_buf[0..6]; + } + while (true) { iperf3_log.info("waiting for connection", .{}); - // try stderr_bw.flush(); + var c = std.process.Child.init( &[_][]const u8{ - if (config.value.iperf3.path) |path| path else "iperf3", + path, "--server", "--port", port, @@ -208,10 +222,6 @@ pub fn main() !void { ); defer data.deinit(); - // try stderr.writeAll(data.items); - // try stderr.writeAll("\n"); - // try stderr_bw.flush(); - var content_length_buf: [16]u8 = undefined; var content_length = try std.fmt.bufPrint( &content_length_buf, @@ -226,6 +236,8 @@ pub fn main() !void { try headers.append("Content-Length", content_length); var req = try client.request(.POST, uri, headers, .{}); + defer req.deinit(); + try req.start(); try req.writeAll(data.items); try req.finish();