[issue28134] socket.socket(fileno=fd) does not work as documented

Yury Selivanov report at bugs.python.org
Fri Dec 15 19:21:50 EST 2017


Yury Selivanov <yselivanov at gmail.com> added the comment:

Let's quickly iterate over what's possible first:

* It's possible to check the type of the FD using "getsockopt(SOL_SOCKET, SO_TYPE)" on all platforms.

* It's possible to check family/proto of the FD using "getsockopt(SOL_SOCKET, SO_DOMAIN/SO_PROTOCOL)" on Linux.

Given the above I propose the following:

1. Passing a wrong type can be considered as a serious error.  SOCK_STREAM is fundamentally different from SOCK_DGRAM.  Because we have a way to validate socket type on all platforms, I propose to do this validation when we create a socket from an FD, and raise an error if the passed socket type isn't correct.

2. When Python is running with '-X dev' (new dev mode added by Victor), I propose to also validate socket.family and socket.proto on Linux, and raise a RuntimeWarning when they don't match.

----------
nosy: +pitrou, vstinner, yselivanov

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28134>
_______________________________________


More information about the Python-bugs-list mailing list