[issue1378] fromfd() and dup() for _socket on WIndows
Christian Heimes
report at bugs.python.org
Wed Nov 14 19:45:05 CET 2007
Christian Heimes added the comment:
Neal, Thomas, what do you think about the patch? Your knowledge of the
Windows API is greater than mine. Is the duplicate_socket() function ok?
I don't want to apply a patch I don't fully understand.
+#ifdef MS_WINDOWS
+/* On Windows a socket is really a handle not an fd */
+static SOCKET
+duplicate_socket(SOCKET handle)
+{
+ HANDLE newhandle;
+
+ if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
+ GetCurrentProcess(), &newhandle,
+ 0, FALSE, DUPLICATE_SAME_ACCESS))
+ {
+ WSASetLastError(WSAEBADF);
+ return INVALID_SOCKET;
+ }
+ return (SOCKET)newhandle;
+}
+#define dup(fd) duplicate_socket(fd)
+#define SOCKETCLOSE closesocket
+#define NO_MAKEFILE /* socket handles can't be treated like file handles */
+#endif
----------
nosy: +nnorwitz, theller
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1378>
__________________________________
More information about the Python-bugs-list
mailing list