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

No method to shutdown socket #34

Open
Sirius902 opened this issue Jun 28, 2021 · 0 comments
Open

No method to shutdown socket #34

Sirius902 opened this issue Jun 28, 2021 · 0 comments

Comments

@Sirius902
Copy link

Sirius902 commented Jun 28, 2021

I have a race condition between two threads, one trying to close a socket and the other reading from it as shown in the code below, but the thread calling recieve needs to be able to yield an error if the socket is closed.

fn recieveLoop(context: *Context) !void {
    while (true) {
        var buffer: [@sizeOf(Input)]u8 = undefined;

        if ((try context.sock.receive(&buffer)) == buffer.len) {
            const held = context.mutex.acquire();
            defer held.release();

            context.input = Input.deserialize(&buffer);
        } else {
            return;
        }
    }
}

If I call close in the other thread then it hits the .WSAENOTSOCK => unreachable, case in recvfrom. Can a method be exposed to cleanly shutdown a socket so there is no race condition?

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