#what is this bug?
1 messages ยท Page 1 of 1 (latest)
this doesnt seem like enough information
can you post a link to your repo?
/ a repro
I don't see any error here - just some functions, and a test that hasn't completed.
could be an infinite loop somewhere, hard to diagnose without more of the code
in my server.test.zig i want to run my server but only execute after each request has been sent, whereas in main.zig i only run start which puts execute in a while loop
inside my execute function there is a while loop, but if i dont make this a while loop my main.zig breaks
i want to have two ways of doing this, executing once, where the client only checks and receives one http request, and executing infinitely for my main, where the client checks and receives http requests continuously
this is the code that is important i think
pub fn start(alloc: Allocator, tcpServer: *std.net.Server) !void {
while (true) {
try execute(alloc, tcpServer);
}
}
pub fn execute(alloc: Allocator, tcpServer: *std.net.Server) !void {
const client = try tcpServer.accept();
handleClient(client, alloc);```
```fn handleClient(connection: net.Server.Connection, alloc: Allocator) void {
defer connection.stream.close();
var read_buffer: [4096]u8 = undefined;
var server = http.Server.init(connection, &read_buffer);
while (server.state == .ready) {
var request = server.receiveHead() catch |err| {
std.log.err("Error receiving request: {s}", .{@errorName(err)});
break;
};
std.log.info("Received {} request for {s}", .{ request.head.method, request.head.target });
handleRequest(&server, &request, alloc) catch |err| {
std.log.err("Error handling request: {s}", .{@errorName(err)});
break;
};
}
}```