Use buffered input stream

This commit is contained in:
daurnimator 2020-05-18 01:26:00 +10:00
parent add13df816
commit 410ac0e5b4
No known key found for this signature in database
GPG Key ID: 45B429A8F9D9D22A

View File

@ -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();