On unix everything is a file approach of function read()
, write()
, close()
is not supported on Win32.
I
If the Windows 'C' library has dup() you could try to dup it, which should fail for a socket but succeed for a file fd. So:
int is_net_socket(fd)
{
return close(dup(fd)) != 0;
}
Warning: untested theory with untested dependency ;-) Note that this would return misleading results if you run out of fd's. Another side effect is that if it is a file it will be flushed and its directory entry updated. All in all it probably sucks frankly. I might even downvote it myself.