New submission from Neil Schemenauer:

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.

----------
components: Library (Lib)
files: fromfd2.txt
messages: 269131
nosy: nascheme
priority: normal
severity: normal
stage: patch review
status: open
title: Add smarter socket.fromfd()
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file43523/fromfd2.txt

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27377>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to