karlseguin / http.zig

An HTTP/1.1 server for zig
MIT License
533 stars 41 forks source link

Evaluate `libxev` usage #24

Closed notramo closed 8 months ago

notramo commented 9 months ago

I just found this Zig library for async I/O. https://github.com/mitchellh/libxev Since async is not in Zig language yet, is it a viable substitute?

karlseguin commented 9 months ago

The issue is the application code.

fn about(_: *httpz.Request, res: *httpz.Response) !void {
  var file = try std.fs.cwd().openFile("example/index.html", .{});
  defer file.close();
  res.body = try file.readToEndAlloc(res.arena, 100000);
}

Until std itself is async, and the libraries (like pg.zig) are async, it's a bit pointless. http.zig itself can be async (and it is), and that helps with protection from DOS and slow clients, but it's an incomplete solution until the entire ecosystem is async.

karlseguin commented 8 months ago

An update. While still not using libxev, the current state of the master branch is that socket reading/writing is async (using epoll or kqueue) and application handlers are executing through a threadpool.