summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-26 22:37:59 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-26 22:37:59 (GMT)
commit28f7ab6402379b53e6ba0b37172c07a28b0726ac (patch)
tree767e0110261d5b17d410291034700109989d8938
parent365171d8f605a950bc62398f73c4fc923be6e7cd (diff)
downloadcpython-28f7ab6402379b53e6ba0b37172c07a28b0726ac.zip
cpython-28f7ab6402379b53e6ba0b37172c07a28b0726ac.tar.gz
cpython-28f7ab6402379b53e6ba0b37172c07a28b0726ac.tar.bz2
Merged revisions 80515 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r80515 | antoine.pitrou | 2010-04-27 00:17:47 +0200 (mar., 27 avril 2010) | 4 lines Hopefully fix sporadic Windows issue by avoiding calling getpeername() on a freshly dup'ed socket. ........
-rw-r--r--Lib/ssl.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 59aff87..68487bd 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -82,6 +82,7 @@ from socket import socket, AF_INET, SOCK_STREAM
import base64 # for DER-to-PEM translation
import traceback
import errno
+import time
class SSLSocket(socket):
@@ -96,6 +97,7 @@ class SSLSocket(socket):
family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None,
suppress_ragged_eofs=True):
+ connected = False
if sock is not None:
socket.__init__(self,
family=sock.family,
@@ -103,26 +105,27 @@ class SSLSocket(socket):
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,