There currently exists a socket library in Python:
Reference: http://docs.python.org/library/socket.html
However, this library does not include functionality for referencing an existing socket based off a file descriptor. I am currently developing Python bindings for a C++ library which opens up a socket first and need a way to reference this opened socket in Python after-the-fact. Keep in mind that this is on Windows (I am using a cross-platform layer of abstraction which neglects file handles).
The code is similar to this:
fd = connect(...) # file descriptor
os.read(fd, buffer)
os.close(fd)
I am looking to find a way to actually define a socket object based off the file descriptor without the by-value duplication found in os.dup and os.dup2.
Would anyone know a way to reference this?
As it doesn’t appear that this question has been answered as of yet (for 1 week), I’ll state my solution.
I implemented an internal binding for retrieving the socket information from within the library, converting the
ctypestopytuples. Because the application itself is wrapped inpy2exe, this modification is unobtrusive to the end-user.