[Python-Dev] Modules/socketmodule.c: avoiding second fcntl() call worth the effort?
Victor Stinner
victor.stinner at gmail.com
Sun Jan 20 23:15:25 CET 2013
Since Linux 2.6.27, it's possible to set SOCK_NONBLOCK directly at the
creation of the socket (using socket() and accept4()). So you don't
need any extra call.
I implemented something similar for SOCK_CLOEXEC flag to implement the
PEP 433. See for example:
http://hg.python.org/features/pep-433/file/1097ffc652f4/Modules/socketmodule.c#l3918
and:
http://hg.python.org/features/pep-433/file/1097ffc652f4/Modules/socketmodule.c#l1950
The PEP 433 (Easier suppression of file descriptor inheritance):
http://python.org/dev/peps/pep-0433/
But I added a new keyword argument to socket.socket() and
socket.socket.accept() for that. I don't know if you can do something
similar without adding a new argument.
--
Instead of two calls to fcntl() (2 syscalls), you can also use "int
opt = 1; ioctl(fd, FIONBIO, &opt);" (1 syscall).
Victor
More information about the Python-Dev
mailing list