tezc / sc

Common libraries and data structures for C.
BSD 3-Clause "New" or "Revised" License
2.23k stars 239 forks source link

sc_sock: WSAPoll is broken #96

Closed svladykin closed 2 years ago

svladykin commented 2 years ago

According to https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/ WSAPoll does not report connection failures (if there is no timeout it just never returns when there is no listener on the other end).

Is that a known issue?

tezc commented 2 years ago

Yes, I know the issue. I added this line as a precaution: https://github.com/tezc/sc/blob/53d4a9158ae74f254194fa776d7091d8f5edda40/socket/sc_sock.c#L1664

Timeout is always set.

As long as WSAPoll() returns, it shouldn't be a problem. It's a good practice to keep a timer inside the application to give up connecting if it takes too long. So, application can delete fd from the WSAPoll if it takes too long (even if the failure is not reported).

Also, if I'm remember correctly, they've fixed this issue in a recent Windows version. (Maybe I'm wrong, I didn't try).

svladykin commented 2 years ago

Looks like you are right, it must be fixed in modern Windows according to https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsapoll

Note  As of Windows 10 version 2004, when a TCP socket fails to connect, (POLLHUP \| POLLERR \| POLLWRNORM) is indicated.