Conceptually this is extremely simple, and I've found that gnulib
already contains useful bits like SOCKET_TO_FD, FD_TO_SOCKET, and the
code for determining if an arbitrary fd is a socket - which is all
great.
Yes, and the read() and write() functions don't need to make this
distinction, because they call ReadFile and WriteFile, which work
equally fine with HANDLEs and SOCKETs.
... but not for all sockets, only those created by gnulib's socket:
/* We have to use WSASocket() to create non-overlapped IO sockets.
Overlapped IO sockets cannot be used with read/write. */
fh = WSASocket (domain, type, protocol, NULL, 0, 0);
Neil, can you make sure that all your sockets are gnulib-created?
((defined _WIN32 || defined __WIN32__)&& !defined __CYGWIN__) is the
solution. (HAVE_WINSOCK2_H&& !defined __CYGWIN__) would be equivalent.
Agreed.
Paolo