[Python-checkins] r80515 - python/branches/py3k/Lib/ssl.py

antoine.pitrou python-checkins at python.org
Tue Apr 27 00:17:47 CEST 2010


Author: antoine.pitrou
Date: Tue Apr 27 00:17:47 2010
New Revision: 80515

Log:
Hopefully fix sporadic Windows issue by avoiding calling getpeername()
on a freshly dup'ed socket.



Modified:
   python/branches/py3k/Lib/ssl.py

Modified: python/branches/py3k/Lib/ssl.py
==============================================================================
--- python/branches/py3k/Lib/ssl.py	(original)
+++ python/branches/py3k/Lib/ssl.py	Tue Apr 27 00:17:47 2010
@@ -83,6 +83,7 @@
 import base64        # for DER-to-PEM translation
 import traceback
 import errno
+import time
 
 class SSLSocket(socket):
 
@@ -97,6 +98,7 @@
                  family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None,
                  suppress_ragged_eofs=True, ciphers=None):
 
+        connected = False
         if sock is not None:
             socket.__init__(self,
                             family=sock.family,
@@ -104,26 +106,27 @@
                             proto=sock.proto,
                             fileno=_dup(sock.fileno()))
             self.settimeout(sock.gettimeout())
+            # see if it's connected
+            try:
+                sock.getpeername()
+            except socket_error as e:
+                if e.errno != errno.ENOTCONN:
+                    raise
+            else:
+                connected = True
             sock.close()
         elif fileno is not None:
             socket.__init__(self, fileno=fileno)
         else:
             socket.__init__(self, family=family, type=type, proto=proto)
 
-        self._closed = False
-
         if certfile and not keyfile:
             keyfile = certfile
-        # see if it's connected
-        try:
-            socket.getpeername(self)
-        except socket_error as e:
-            if e.errno != errno.ENOTCONN:
-                raise
-            # no, no connection yet
-            self._sslobj = None
-        else:
-            # yes, create the SSL object
+
+        self._closed = False
+        self._sslobj = None
+        if connected:
+            # create the SSL object
             try:
                 self._sslobj = _ssl.sslwrap(self, server_side,
                                             keyfile, certfile,


More information about the Python-checkins mailing list