Opened 7 years ago

Last modified 7 years ago

#4389 enhancement new

Bindings for WSADuplicateSocket

Reported by: Glyph Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: zseil Branch:


Similar to the analogous functionality on UNIX, this function is not available in Python, or even PyWin32. (I suppose Mark Hammond thought that the socket module would be an adequate wrapper for winsock, so there doesn't appear to be any socket-related functionality in PyWin32 proper.)

Change History (5)

comment:1 Changed 7 years ago by Glyph

In order to be of any use, we may need to also add extended bindings to WSASocket so we can pass along the lpProtocolInfo parameter. See the Remarks section of the documentation for WSADuplicateSocket for more information.

comment:2 Changed 7 years ago by Jean-Paul Calderone

Maybe this is something to ask for from pywin32? Perhaps it would be an easy addition there.

comment:3 Changed 7 years ago by zseil

Cc: zseil added

This would be hard to implement in pywin32, since Python on Windows doesn't expose any API for creating socket objects from third party modules, meaning that pywin32 would have to duplicate the complete socket interface. pywin32 does provide quite a few socket related functions otherwise, in the win32file module.

Providing a socket.fromfd in Python also wouldn't be trivial, since it would have to be implemented using WSADuplicateSocket and WSASocket (DuplicateHandle does not work reliably with sockets). This would require porting the socket module to Winsock2.

comment:4 Changed 7 years ago by jknight

Hey, it's not as bad as all that. You should be able to initialize a PySocketSockObject yourself. It's only two short functions, new_sockobject and init_sockobject. And, init_sockobject looks like it's dllexported (maybe by accident, though?) so you only really need to copy new_sockobject.

And that function doesn't even need to have the struct layout defined, so you don't even need to worry about that socketmodule.h isn't part of python's devel headers, so you don't get an easily accessible definition of PySocketSockObject!

comment:5 Changed 6 years ago by <automation>

Owner: PenguinOfDoom deleted
Note: See TracTickets for help on using tickets.