]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Simplify dns.query._connect(). 477/head
authorBrian Wellington <bwelling@xbill.org>
Wed, 20 May 2020 23:48:04 +0000 (16:48 -0700)
committerBrian Wellington <bwelling@xbill.org>
Wed, 20 May 2020 23:48:04 +0000 (16:48 -0700)
dns/query.py

index de5c300bb87bd540ba77564501167c4ffd874b94..080a66ddba8a9a9d5dbdd0a9f35d1eda7ae1b7ee 100644 (file)
@@ -590,21 +590,14 @@ def receive_tcp(sock, expiration=None, one_rr_per_rrset=False,
     return (r, received_time)
 
 def _connect(s, address, expiration):
-    try:
-        s.connect(address)
-    except socket.error:
-        (ty, v) = sys.exc_info()[:2]
-
-        if hasattr(v, 'errno'):
-            v_err = v.errno
-        else:
-            v_err = v[0]
-        if v_err not in [errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EALREADY]:
-            raise v
+    err = s.connect_ex(address)
+    if err == 0:
+        return
+    if err in (errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EALREADY):
         _wait_for_writable(s, expiration)
         err = s.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
-        if err != 0:
-            raise OSError(err, os.strerror(err)) from None
+    if err != 0:
+        raise OSError(err, os.strerror(err))
 
 
 def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,