I need to determine if the descriptor that my code did not generate is for which GetFileType()==FILE_TYPE_PIPEis a socket or not. There is no API for this.
I have tried the following. The general idea is to use a socket-specific function and treat the failure as a non-socket value.
getsockopt()- This was my first attempt. Unfortunately, this is similar to freezing when called by many threads on the same (non-socket) descriptor.WSAEnumNetworkEvents() - this is what Gnulib does, but will have unwanted side effects if the handle is a socket.getpeername()is what cygwin does, but it won’t work for some sockets either. Guess if the error does not mean that the socket does not seem reliable and safe in the future.
I do not mind if the solution only works on some versions of Windows, for example. Vista, I can always return to another method in the general case.
source
share