New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socket.fromfd()'s API is difficult or impossible to use correctly in general #62591
Comments
socket.fromfd() requires you to supply at least the family and type of (For instance, in Python 3 calling .getsockname() may raise Suggested resolution: socket.fromfd() should always determine the Less appealing resolution: the socket module should provide officially |
Unfortunately it's not as easy as you may think. BSD sockets have no portable API to retrieve domain, type and protocol from a file descriptor. getsockopt() may be able to retrieve some or even all values but it's not portable. For example SO_DOMAIN and SO_PROTOCOL requires Linux 2.6.32 or newer. I'm not sure about BSD or Windows. It's also not possible to verify the parameters until you actually do an operation like send(), recv() or accept() on a fd. Wrong parameters may not raise an error after all. For now I suggest that you pass all information to the other process, that is fd, domain, type, proto. They are just integers. |
As far as I know, you can recover everything except the protocol As for the other suggestion: When Python is plugging into larger systems or APIs that pass sockets I do want to be able to write Python programs that can interact in |
It would be nice for this to be fixed in a 2.7.x release too, if possible, since the workaround involves a ton of extra system calls and there's no other way to construct a socket object directly. |
Do you want to work on a patch for 3.4? You have about five days until 3.4 is going into feature freeze. |
fromfd() can be simplified after bpo-26907 has landed. |
I've created a patch to add fromfd2(). I think it addresses the original concern of this issue. My patch also adds the constants suggested by Issue bpo-26907. |
Sorry, forgot to link the patch: Issue bpo-27377. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: