[New-bugs-announce] [issue23834] socketmodule.c: add sock_call() to fix how the timeout is recomputed

STINNER Victor report at bugs.python.org
Wed Apr 1 00:55:06 CEST 2015


New submission from STINNER Victor:

With the PEP 475, the BEGIN_SELECT_LOOP and END_SELECT_LOOP macros of Modules/socketmodule.c became complex. Moreover, they are misused to handle EINTR. Most functions currently reimplemented their own loop inside the existing "select loop", and so the timeout is not recomputed correctly.

Attached patch replaces the two macros with a new sock_call() function which takes a function as a parameter. IMO, the new code (sock_xxx_impl functions) is simpler to read, understand and debug.

I hate debugging code (especially in gdb) using complex macros.

Copy of sock_call() documentation:

/* Call a socket function.

   If the socket has a timeout, wait until the socket is ready before calling
   the function: wait until the socket is writable if writing is nonzero, wait
   until the socket received data otherwise.

   If the function is interrupted by a signal (failed with EINTR): retry the
   function, except if the signal handler raised an exception (PEP 475).

   When the function is retried, recompute the timeout using a monotonic clock.

   Raise an exception and return -1 on error, return 0 on success. */

I was surprised by the number of lines of code. It probably means that we are solving a non trivial problem: calling correctly socket functions with a timeout and retrying when interrupted by a signal.

----------
files: sock_call.patch
keywords: patch
messages: 239758
nosy: haypo, neologix, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: socketmodule.c: add sock_call() to fix how the timeout is recomputed
versions: Python 3.5
Added file: http://bugs.python.org/file38769/sock_call.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23834>
_______________________________________


More information about the New-bugs-announce mailing list