This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nascheme
Recipients nascheme
Date 2016-06-23.18:33:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1466706816.6.0.72770597716.issue27377@psf.upfronthosting.co.za>
In-reply-to
Content
When implementing server software that inherits a socket via a file descriptor, it is useful to be able to query the descriptor and find out what kind of socket has been passed.  This can be done with getsockopt() and getsockname().  Python does not expose a clean way to do this.

One example use case is receiving an open socket from systemd.  For example, systemd will pass the open socket using file descriptor 3.  It would be handy if the Python server did not have to hard-code the type of the socket but instead could determine it.  This patch provides a function that, when given an integer file descriptor, returns a Python socket object with the correct family and kind/type attributes.  This seems like a useful, high-level interface.

This patch adds two new functions to the socket module.  I'm not so happy about the names.  Suggestions welcome.  The fromfd2() function does not duplicate the file descriptor.  I think this was a design mistake in fromfd().  If it wasn't for the duplication, I would change fromfd() to have None as default arguments and then use fdtype() to get the family, kind and protocol.  The fdtype() function returns (family, type, proto) for an integer file descriptor.

There does not appear to be any way to query the protocol of the passed socket.  I just assume it is zero.
History
Date User Action Args
2016-06-23 18:33:36naschemesetrecipients: + nascheme
2016-06-23 18:33:36naschemesetmessageid: <1466706816.6.0.72770597716.issue27377@psf.upfronthosting.co.za>
2016-06-23 18:33:36naschemelinkissue27377 messages
2016-06-23 18:33:35naschemecreate