move ArenaAllocator into Server

This commit is contained in:
Techatrix 2022-08-01 00:44:07 +02:00
parent 805148125c
commit fca78a98b0
3 changed files with 188 additions and 222 deletions

File diff suppressed because it is too large Load Diff

View File

@ -23,20 +23,16 @@ fn loop(server: *Server) !void {
var reader = std.io.getStdIn().reader();
while (server.keep_running) {
// Arena used for temporary allocations while handling a request
var arena = std.heap.ArenaAllocator.init(server.allocator);
defer arena.deinit();
const headers = readRequestHeader(arena.allocator(), reader) catch |err| {
const headers = readRequestHeader(server.allocator, reader) catch |err| {
logger.err("{s}; exiting!", .{@errorName(err)});
return;
};
const buffer = try arena.allocator().alloc(u8, headers.content_length);
const buffer = try server.allocator.alloc(u8, headers.content_length);
try reader.readNoEof(buffer);
var writer = std.io.getStdOut().writer();
try server.processJsonRpc(writer, &arena, buffer);
try server.processJsonRpc(writer, buffer);
}
}

View File

@ -38,9 +38,6 @@ const Context = struct {
params: []const u8,
expect: ?[]const u8,
) !void {
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
var output = std.ArrayList(u8).init(allocator);
defer output.deinit();
@ -52,7 +49,7 @@ const Context = struct {
defer allocator.free(req);
// send the request to the server
try self.server.processJsonRpc(output.writer(), &arena, req);
try self.server.processJsonRpc(output.writer(), req);
// if we don't expect a response ignore it
const expected = expect orelse return;