Skip to content

Commit

Permalink
Move away from oneshot (epoll) / dispatch (kqueue)
Browse files Browse the repository at this point in the history
Result in way less system calls, significant performance boost, but more
complicated thread-safety code.
  • Loading branch information
karlseguin committed Oct 19, 2024
1 parent dc399be commit 3b77c62
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 196 deletions.
9 changes: 2 additions & 7 deletions src/httpz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ pub fn Server(comptime H: type) type {
var req = Request.init(allocator, conn);
var res = Response.init(allocator, conn);

defer std.debug.assert(res.written == true);

if (comptime std.meta.hasFn(Handler, "handle")) {
if (comptime @typeInfo(@TypeOf(Handler.handle)).@"fn".return_type != void) {
@compileError(@typeName(Handler) ++ ".handle must return 'void'");
Expand Down Expand Up @@ -668,13 +670,6 @@ pub fn upgradeWebsocket(comptime H: type, req: *Request, res: *Response, ctx: an
return true;
}

// fn websocketHandler(comptime H: type, server: *websocket.Server, stream: std.net.Stream, context: anytype) void {
// errdefer stream.close();
// var conn = server.newConn(stream);
// var handler = H.init(&conn, context) catch return;
// server.handle(H, &handler, &conn);
// }

// std.heap.StackFallbackAllocator is very specific. It's really _stack_ as it
// requires a comptime size. Also, it uses non-public calls from the FixedBufferAllocator.
// There should be a more generic FallbackAllocator that just takes 2 allocators...
Expand Down
2 changes: 1 addition & 1 deletion src/request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ test "request: fuzz" {
const number_of_requests = random.uintAtMost(u8, 10) + 1;

for (0..number_of_requests) |_| {
defer ctx.conn.keepalive(4096);
defer ctx.conn.requestDone(4096);
const method = randomMethod(random);
const url = t.randomString(random, aa, 20);

Expand Down
1 change: 0 additions & 1 deletion src/response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ pub const Response = struct {
.{ .len = header_buf.len, .base = header_buf.ptr },
.{ .len = body.len, .base = body.ptr },
};

try writeAllIOVec(stream.handle, &vec);
}

Expand Down
2 changes: 1 addition & 1 deletion src/t.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub const Context = struct {

const conn = aa.create(Conn) catch unreachable;
conn.* = .{
.state = .request,
._state = .request,
.handover = .close,
.stream = server,
.address = std.net.Address.initIp4([_]u8{ 127, 0, 0, 200 }, 0),
Expand Down
Loading

0 comments on commit 3b77c62

Please sign in to comment.