[Python-ideas] Extend socket.accept to put accepted socket in non-blocking mode
Saúl Ibarra Corretgé
saghul at gmail.com
Fri Mar 7 10:37:58 CET 2014
Hi,
(I hope this list is the right place for this)
I was browsing around for accept4 usage in Python and I saw it's already
used internally in socket.accept (on Linux only), albeit it's not
exposed, so accepting an incoming connection and setting it to be
non-blocking takes 3 syscalls.
accept4 allows us to do this with a single syscall, and it made it into
FreeBSD 10, so that's another system that could benefit from this
optimization.
Would it be desirable to extend socket.accept to something like:
socket.accept(set_non_blocking=False)
which would use accept4's flags on supported systems and fallback to
regular fcntl on others?
The idea is to accept an incoming connection and make it non-blocking at
the same time, asyncio and other frameworks would benefit from this by
doing one function call and 2 syscalls less (on supported systems, that is).
Cheers,
--
Saúl Ibarra Corretgé
bettercallsaghul.com
More information about the Python-ideas
mailing list