karlseguin / websocket.zig

A websocket implementation for zig
MIT License
283 stars 25 forks source link

Writing to Socket from Another Thread #36

Closed edqx closed 2 months ago

edqx commented 2 months ago

Perhaps this is more of an Operating System problem- on Linux, I can spawn another thread and write to a connection using any of the write methods provided. On Windows, it hangs on std.net.Stream.write:

https://github.com/ziglang/zig/blob/cb308ba3ac2d7e3735d1cb42ef085edb1e6db723/lib/std/net.zig#L1863

I'm using the latest version of the library with Zig 0.13.0.

Is this a limitation of the library, of the Zig standard library, of my operating system (Windows) or of something else? What's the suggested way to send messages from a background thread?

karlseguin commented 2 months ago

The library doesn't do anything fancy with sockets, and I'm under the impression that this type of behavior should be fine on windows. I found this issue which I believe is what you're seeing.

edqx commented 2 months ago

Thanks for the reply, that issue looks likely to be the same since presumably the WebSocket server immediately starts reading before the other thread can start writing. I don't have time to look much into it, so if it's just Zig standard library issue then I guess I'll just use WSL2, which works fine.