If select() raises an exception due to EINTR, we should just select()
authorBob Halley <halley@dnspython.org>
Sun, 25 Nov 2007 17:28:03 +0000 (17:28 +0000)
committerBob Halley <halley@dnspython.org>
Sun, 25 Nov 2007 17:28:03 +0000 (17:28 +0000)
again.  Thanks to Geert Jansen for reporting this.

ChangeLog
dns/query.py

index 00aeb5d7950cf57e4020309704fee50c47b29da1..e62fa4f18f312e4234d2d627acedf68ec691cd56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+
+2007-11-25  Bob Halley  <halley@dnspython.org
+
+       * dns/query.py (_wait_for): if select() raises an exception due to
+         EINTR, we should just select() again.
+
 2007-06-13  Bob Halley  <halley@dnspython.org>
 
        * dns/inet.py: Added is_multicast().
index ed4eff3ac739939e7b8738eeaa150a10a3aeae7c..c6f1f6524736d1e4c61189dc39dc241fa9625895 100644 (file)
@@ -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: