This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients neologix, pitrou, serhiy.storchaka, vstinner
Date 2015-03-31.22:55:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427842506.28.0.704301607448.issue23834@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-03-31 22:55:07vstinnersetrecipients: + vstinner, pitrou, neologix, serhiy.storchaka
2015-03-31 22:55:06vstinnersetmessageid: <1427842506.28.0.704301607448.issue23834@psf.upfronthosting.co.za>
2015-03-31 22:55:06vstinnerlinkissue23834 messages
2015-03-31 22:55:06vstinnercreate