New submission from Yury Selivanov <yseliva...@gmail.com>: On Linux, socket type is both a socket type and a bit mask (of SOCK_CLOEXEC and SOCK_NONBLOCK). Therefore, anyone who write code like 'if sock.type == SOCK_STREAM' writes non-portable code, that occasionally breaks on Linux.
This caused some hard to spot bugs in asyncio already: https://bugs.python.org/issue27456 -- this one was discovered only 1 year after the actual change. On Linux, in 'include/linux/net.h' there's a SOCK_TYPE_MASK macro defined to 0xF. The idea is that on Linux you should mask socket type before comparing it to SOCK_STREAM or other socket types. Using socket.SOCK_NONBLOCK on Python was always error-prone even if one targets only Linux. For instance, socket.type won't be updated to include SOCK_NONBLOCK if the socket was updated via ioctl call directly. Therefore, I propose to fix socket.type getter to always (on Linux) apply that mask in Python. ---------- components: Library (Lib) messages: 308363 nosy: asvetlov, inada.naoki, pitrou, vstinner, yselivanov priority: normal severity: normal status: open title: apply SOCK_TYPE_MASK to socket.type on Linux type: enhancement versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32331> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com