Fix Issue9753: socket.dup() does not always work right on Windows
authorDaniel Stutzbach <daniel@stutzbachenterprises.com>
Fri, 3 Sep 2010 12:38:33 +0000 (12:38 +0000)
committerDaniel Stutzbach <daniel@stutzbachenterprises.com>
Fri, 3 Sep 2010 12:38:33 +0000 (12:38 +0000)
Misc/NEWS
Modules/socketmodule.c

index 4053dd76d33e5943d1c6015f0fc6a700b9425481..45e27c612b42c8bc3064d1763523851117f5979f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -155,6 +155,9 @@ Extensions
 Library
 -------
 
+- Issue #9753: Fixed socket.dup, which did not always work correctly
+  on Windows.
+
 - Issue #7005: Fixed output of None values for RawConfigParser.write and
   ConfigParser.write.
 
index 8c743d87f5e607f251e11abb5fe19c99da52e753..6ebb9d938506d5c4d31fdd7de83a7dc5543bee2d 100644 (file)
@@ -351,16 +351,13 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
 static SOCKET
 dup_socket(SOCKET handle)
 {
-    HANDLE newhandle;
+    WSAPROTOCOL_INFO info;
 
-    if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
-                         GetCurrentProcess(), &newhandle,
-                         0, FALSE, DUPLICATE_SAME_ACCESS))
-    {
-        WSASetLastError(GetLastError());
+    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