Add uv timer for TCP connection timeouts
Currently, the TCP connection timeouts is configured using a socket option that varies with the platforms:
- On Linux, it's
TCP_USER_TIMEOUT
(in miliseconds) - On Windows, it's called
TCP_MAXRT
(in seconds) - On macOS, there are two! socket options:
TCP_CONNECTIONTIMEOUT
(in seconds) andTCP_RXT_CONNDROPTIME
(documented just in the header) - On FreeBSD 11 and FreeBSD 12, the option is called
TCP_KEEPINIT
(in seconds)
Alas, at least OpenBSD and NetBSD doesn't have any socket option like this, so a system-wide default is used (and it can be large) leading to connection callback not being called in quite a long time -> thus the unit test might crash on shutdown because there's dangling nmsocket
waiting for connection.
We need to restore the connection timeout handler that will:
- call
uv_close()
on the connectionuv_tcp_t
in the timeout handle forcing the connection callback to be called with the timeout error code - properly handle that case where the
uv_tcp_t
is closed out of order