diff options
Diffstat (limited to 'winsup/cygwin/fhandler_socket.cc')
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 01965bf67..7617bc23b 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -344,6 +344,7 @@ fhandler_socket::fixup_after_fork (HANDLE parent) prot_info_ptr, 0, 0)) == INVALID_SOCKET) { debug_printf ("WSASocket error"); + set_io_handle ((HANDLE)INVALID_SOCKET); set_winsock_errno (); } else if (!new_sock && !winsock2_active) @@ -385,13 +386,34 @@ fhandler_socket::dup (fhandler_base *child) fhs->set_sun_path (get_sun_path ()); fhs->set_socket_type (get_socket_type ()); - fhs->fixup_before_fork_exec (GetCurrentProcessId ()); - if (winsock2_active) + /* Using WinSock2 methods for dup'ing sockets seem to collide + with user context switches under... some... conditions. So we + drop this for NT systems at all and return to the good ol' + DuplicateHandle way of life. This worked fine all the time on + NT anyway and it's even a bit faster. */ + if (!wincap.has_security ()) { - fhs->fixup_after_fork (hMainProc); - return 0; + fhs->fixup_before_fork_exec (GetCurrentProcessId ()); + if (winsock2_active) + { + fhs->fixup_after_fork (hMainProc); + return get_io_handle () == (HANDLE) INVALID_SOCKET; + } + } + /* We don't call fhandler_base::dup here since that requires to + have winsock called from fhandler_base and it creates only + inheritable sockets which is wrong for winsock2. */ + HANDLE nh; + if (!DuplicateHandle (hMainProc, get_io_handle (), hMainProc, &nh, 0, + !winsock2_active, DUPLICATE_SAME_ACCESS)) + { + system_printf ("dup(%s) failed, handle %x, %E", + get_name (), get_io_handle ()); + __seterrno (); + return -1; } - return fhandler_base::dup (child); + child->set_io_handle (nh); + return 0; } int __stdcall |