From 410ac0e5b4319ea2a9c5f9f114acdd44be6d9a36 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 18 May 2020 01:26:00 +1000 Subject: [PATCH] Use buffered input stream --- src/main.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index a5d78fe..3ac5ea5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -618,7 +618,9 @@ pub fn main() anyerror!void { // Init global vars - const stdin = std.io.getStdIn().inStream(); + var buffered_stdin = std.io.bufferedInStream(std.io.getStdIn().inStream()); + const in_stream = buffered_stdin.inStream(); + stdout = std.io.getStdOut().outStream(); // Read the configuration, if any. @@ -664,14 +666,14 @@ pub fn main() anyerror!void { defer json_parser.deinit(); while (true) { - const headers = readRequestHeader(allocator, stdin) catch |err| { + const headers = readRequestHeader(allocator, in_stream) catch |err| { try log("{}; exiting!", .{@errorName(err)}); return; }; defer headers.deinit(allocator); const buf = try allocator.alloc(u8, headers.content_length); defer allocator.free(buf); - try stdin.readNoEof(buf); + try in_stream.readNoEof(buf); try processJsonRpc(&json_parser, buf, config); json_parser.reset();