Rewrite Windows connect()

Our old code wasn't working with projects like Qt that call connect() in
O_NONBLOCK mode multiple times. This change overhauls connect() to use a
simpler WSAConnect() API and follows the same pattern as cosmo accept().
This change also reduces the binary footprint of read(), which no longer
needs to depend on our enormous clock_gettime() function.
This commit is contained in:
Justine Tunney 2024-09-12 23:01:20 -07:00
parent 5469202ea8
commit e142124730
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
25 changed files with 556 additions and 277 deletions

View file

@ -31,12 +31,23 @@
/**
* Connects socket to remote end.
*
* ProTip: Connectionless sockets, e.g. UDP, can be connected too. The
* benefit is not needing to specify the remote address on each send. It
* also means getsockname() can be called to retrieve routing details.
* When `fd` is in `O_NONBLOCK` mode, this raises `EINPROGRESS`. To wait
* for establishment poll() function may be called using `POLLOUT`. Then
* `SO_ERROR` may be used to check for errors.
*
* Connectionless sockets, e.g. UDP, can be connected too. The benefit
* is not needing to specify the remote address on each send. It also
* means getsockname() can be called to retrieve routing details.
*
* On Linux, your `SO_SNDTIMEO` will timeout connect(). Other OSes (i.e.
* Windows, MacOS, and BSDs) do not support this and will block forever.
*
* On Windows, when this function blocks, there may be a 10 millisecond
* delay on the handling of signals or thread cancelation.
*
* @return 0 on success or -1 w/ errno
* @raise EALREADY if a non-blocking connection request already happened
* @raise EINPROGRESS if `O_NONBLOCK` and connecting process initiated
* @raise EALREADY if a `O_NONBLOCK` connecting already in flight
* @raise EADDRINUSE if local address is already in use
* @raise EINTR if a signal handler was called instead
* @raise ENETUNREACH if network is unreachable