diff Modules/socketmodule.c @ 64392:7d1752d62050

Fix Issue9753: socket.dup() does not always work right on Windows
author Daniel Stutzbach <daniel@stutzbachenterprises.com>
date Fri, 03 Sep 2010 12:38:33 +0000
parents 2ccd043aad5c
children aed04b3f0fe3
line wrap: on
line diff
--- a/Modules/socketmodule.c	Fri Sep 03 11:11:43 2010 +0000
+++ b/Modules/socketmodule.c	Fri Sep 03 12:38:33 2010 +0000
@@ -351,16 +351,13 @@
 static SOCKET
 dup_socket(SOCKET handle)
 {
-    HANDLE newhandle;
-
-    if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
-                         GetCurrentProcess(), &newhandle,
-                         0, FALSE, DUPLICATE_SAME_ACCESS))
-    {
-        WSASetLastError(GetLastError());
+    WSAPROTOCOL_INFO info;
+
+    if (WSADuplicateSocket(handle, GetCurrentProcessId(), &info))
         return INVALID_SOCKET;
-    }
-    return (SOCKET)newhandle;
+
+    return WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
+                     FROM_PROTOCOL_INFO, &info, 0, 0);
 }
 #define SOCKETCLOSE closesocket
 #else