Skip to content

close without callback #126

Open
Open
@aep

Description

@aep

trying to close a socket inside accept has some confusing api usage.
it's not entirely clear what the callback is for and how to use it correctly

    var server_conn: ?xev.TCP = null;
    server.accept(&loop, &c_accept, ?xev.TCP, &server_conn, (struct {
        fn callback(
            _: ?*?xev.TCP,
            loop2: *xev.Loop,
            _: *xev.Completion,
            r: xev.AcceptError!xev.TCP,
        ) xev.CallbackAction {
            std.log.info("accepted", .{});

           var sock = r catch unreachable;
            var c_why: xev.Completion = undefined;
            defer sock.close(loop2, &c_why, void, null, closeCallback);



            return .rearm;
        }
    }).callback);
[1] aep@MacBookAir: ~/work/zig/httpd zig build && ./zig-out/bin/httpd
info: accepted
thread 1006309 panic: switch on corrupt value
/Users/aep/.cache/zig/p/12208fa7b1c9723ab1e97548595cda3810e881e17e8a7d367eaab75b3408848277d5/src/backend/kqueue.zig:889:17: 0x10013d64f in stop_completion (httpd)
        switch (c.op) {
                ^
/Users/aep/.cache/zig/p/12208fa7b1c9723ab1e97548595cda3810e881e17e8a7d367eaab75b3408848277d5/src/backend/kqueue.zig:180:50: 0x10013a48b in submit (httpd)
                    .dead => self.stop_completion(c),
                                                 ^
/Users/aep/.cache/zig/p/12208fa7b1c9723ab1e97548595cda3810e881e17e8a7d367eaab75b3408848277d5/src/backend/kqueue.zig:333:24: 0x10013ee7b in tick (httpd)
        try self.submit();
                       ^
/Users/aep/.cache/zig/p/12208fa7b1c9723ab1e97548595cda3810e881e17e8a7d367eaab75b3408848277d5/src/backend/kqueue.zig:264:62: 0x100140bd3 in run (httpd)
            .until_done => while (!self.done()) try self.tick(1),
                                                             ^
/Users/aep/work/zig/httpd/src/main.zig:43:17: 0x100140fef in main (httpd)
    try loop.run(.until_done);
                ^
/Users/aep/zig/0.13.0/files/lib/std/start.zig:524:37: 0x10014165f in main (httpd)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x196894273 in ??? (???)
???:?:?: 0x0 in ??? (???)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions