Open zwetan opened 7 years ago
in WinPortUtils2.cpp
we have WIN32_is_socket()
which allow us to detect if a descriptor is actually a file or a socket.
scenario would be
move our definition from win32-platform2.h
#define VMPI_dup ::_dup
to VMPI2.h
// ---- C.unistd ----
extern int VMPI_ dup(int fildes);
and in the the implementation (pseudo code)
int VMPI_dup(int fildes)
{
SOCKET sd = FD_TO_SOCKET(fildes);
if( WIN32_is_socket( sd ) )
{
// use WSADuplicateSocket() to duplicate
}
return _dup( fildes );
}
see _dup
dup() under POSIX can duplicate file and socket descriptor but under WIN32 can only duplicate file descriptor.
see Winsock Programmer’s FAQ - BSD Sockets Compatibility
see WSADuplicateSocket()