Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close without callback #126

Open
aep opened this issue Nov 8, 2024 · 0 comments
Open

close without callback #126

aep opened this issue Nov 8, 2024 · 0 comments

Comments

@aep
Copy link

aep commented Nov 8, 2024

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 ??? (???)
@aep aep changed the title nested loop is const close without callback Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant