emscripten-core / emscripten-core/emscripten
`select`/`poll` with timeout does not block
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I noticed a high CPU usage for the WASM port of our product and traced it to an infinite `select()` loop in `boost::asio` sockets, see [`socket_ops.ipp`](https://github.com/boostorg/asio/blob/b6dcb1a5be22cec32888c84d22169189f129e4a1/include/boost/asio/detail/impl/socket_ops.ipp#L2267), because the syscall does not use the timeout. We're using the default emulated TCP over web sockets implementation. `select()` is called on a PThread.
I wonder: why is this? It seems that `emscripten_proxy_sync` should be able to block just fine on a worker PThread.
Are there any plans to support blocking? How would you guys recommend solving this? Is the only option to use the WebSockets API directly instead? Should Boost fix this for the Emscripten case (they have more Emscripten-specific code blocks)?
Related: #19447, but that's about full POSIX Sockets over a WebSocket proxy server.
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.19 (08e2de1031913e4ba7963b1c56f35f036a7d4d56)
clang version 22.0.0git (https:/github.com/llvm/llvm-project 12f392cff10fcc70b4ec4f01ab386922742e9136)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/swdv/emsdk/upstream/bin
```
Contributor guide
Assessment
This issue has not been assessed yet.