move ArenaAllocator into Server
This commit is contained in:
parent
805148125c
commit
fca78a98b0
395
src/Server.zig
395
src/Server.zig
File diff suppressed because it is too large
Load Diff
10
src/main.zig
10
src/main.zig
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user