mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
If the timeout to net::poll() is -1, poll() will block until a requested
event occurs. However, in the poll() function, the Duration timeout is
converted to milliseconds (Duration is in microseconds). The conversion
involves integer arithmetics which results in a zero timeout (= -1 /
1000), i.e. poll() will return immediately and the following accept will
fail.
To fix this, only convert to milliseconds if timeout paramter is
non-negative.
Example to reproduce the error:
```
module echo;
import std::io, std::net;
fn void main()
{
TcpServerSocket server = tcp::listen("localhost", 6969, 69, REUSEADDR)!!;
server.sock.set_non_blocking(true)!!;
Poll[*] polls = {{ .socket = server.sock, .events = net::SUBSCRIBE_READ }};
if (catch net::poll(polls[..], net::POLL_FOREVER)) io::printn("poll error");
TcpSocket client = tcp::accept(&server)!!;
io::printn("OK");
}
```
Poll() will return immediately and the following tcp::accept() will fail
with an "ACCEPT_FAILED" error.
Reported-by: Alexey Kutepov <reximkut@gmail.com>