0

There are many questions looking similarly but I did not find anything close to the issue I am trying to figure out. I am using the same code on Linux (RedHat, GCC) and Windows (MSVC). POSIX API is used in the both cases and the differences are subtle.

  1. A socket is created (::socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)), TCP_NODELAY option is set.
  2. A special case come here:
    • The address to connect cannot be resolved (the server does not exist) so no 'connect' is called for this socket;
    • Nobody bothers whether the connect failed, has not been called or anything else;
    • This is a 3rd-party library so I cannot say why this implementation has been chosen.
  3. Now, the socket is fed to 'select' (writing+exceptions). The expectation is that some event (write/except) should be fired and then the time comes to see the actual state (connected, disconnected, whatsoever) and take required care.

RedHat/GCC behaves this expected way indeed. Bare socket (no connection ever attempted) signals a write event being fed to select. Windows/MSVC gets no event from such a call to select. Nothing is signaled ever. I tried to see what happens on Windows/GCC and yes, it behaves like RedHat/GCC, a write event is fired for never connected socket.

I am wondering, is this the way POSIX select should behave? Is this a kind of platform-dependent? Or am I missing an available socket option to force Windows/MSVC's select to behave like GCC?

Mtm 3.14
  • 29
  • 5
  • Winsock isn't posix and doesn't pretend to be. I wouldn't expect the same behavior in unusual edge cases like trying to select an unconnected socket. – Shawn Mar 09 '23 at 02:14

0 Answers0