New submission from Chris Siebenmann: socket.fromfd() requires you to supply at least the family and type of the file descriptor that you are turning into a Python socket object. However the socket module provides no documented way to determine what these actually are and there are any number of situations where you may get handed file descriptors with an indeterminate type. Nor does providing incorrect family and type values raise an exception from fromfd(), although if you get the wrong values you may get exceptions from calling methods on the returned socket (you can also get garbled and nonsensical results from some methods).
(For instance, in Python 3 calling .getsockname() may raise UnicodeDecodeError under some circumstances.) Suggested resolution: socket.fromfd() should always determine the family and type itself and the arguments for them should become optional. If they are supplied and they do not match the determined family and type, fromfd() should probably raise an exception (although that will break some existing code). Less appealing resolution: the socket module should provide officially documented and supported methods for determining the family and type of a (socket) file descriptor. I think that a new module function to do this would be the cleanest approach. ---------- components: Library (Lib) messages: 192500 nosy: cks priority: normal severity: normal status: open title: socket.fromfd()'s API is difficult or impossible to use correctly in general type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18391> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com