From d76fd330f1454de7a0071a93c2dfc7713c083bcb Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sun, 25 Nov 2007 17:28:03 +0000 Subject: [PATCH] If select() raises an exception due to EINTR, we should just select() again. Thanks to Geert Jansen for reporting this. --- ChangeLog | 6 ++++++ dns/query.py | 39 +++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 00aeb5d7..e62fa4f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ + +2007-11-25 Bob Halley * dns/inet.py: Added is_multicast(). diff --git a/dns/query.py b/dns/query.py index ed4eff3a..c6f1f652 100644 --- a/dns/query.py +++ b/dns/query.py @@ -44,24 +44,31 @@ def _compute_expiration(timeout): return None else: return time.time() + timeout - + def _wait_for(ir, iw, ix, expiration): - if expiration is None: - timeout = None - else: - timeout = expiration - time.time() - if timeout <= 0.0: + done = False + while not done: + if expiration is None: + timeout = None + else: + timeout = expiration - time.time() + if timeout <= 0.0: + raise dns.exception.Timeout + try: + if timeout is None: + (r, w, x) = select.select(ir, iw, ix) + else: + (r, w, x) = select.select(ir, iw, ix, timeout) + except select.error, e: + if e.args[0] != errno.EINTR: + raise e + done = True + if len(r) == 0 and len(w) == 0 and len(x) == 0: raise dns.exception.Timeout - if timeout is None: - (r, w, x) = select.select(ir, iw, ix) - else: - (r, w, x) = select.select(ir, iw, ix, timeout) - if len(r) == 0 and len(w) == 0 and len(x) == 0: - raise dns.exception.Timeout - + def _wait_for_readable(s, expiration): _wait_for([s], [], [s], expiration) - + def _wait_for_writable(s, expiration): _wait_for([], [s], [s], expiration) @@ -91,7 +98,7 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, @param ignore_unexpected: If True, ignore responses from unexpected sources. The default is False. @type ignore_unexpected: bool""" - + wire = q.to_wire() if af is None: try: @@ -191,7 +198,7 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0): @param source_port: The port from which to send the message. The default is 0. @type source_port: int""" - + wire = q.to_wire() if af is None: try: -- 2.47.3