]> granicus.if.org Git - python/commitdiff
Merged revisions 80456 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 24 Apr 2010 22:07:51 +0000 (22:07 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 24 Apr 2010 22:07:51 +0000 (22:07 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r80456 | antoine.pitrou | 2010-04-25 00:04:40 +0200 (dim., 25 avril 2010) | 5 lines

  Issue #8524: When creating an SSL socket, the timeout value of the
  original socket wasn't retained (instead, a socket with a positive timeout
  would be turned into a non-blocking SSL socket).
........

Lib/ssl.py
Lib/test/test_ssl.py
Misc/NEWS

index ebb11b49c5689b2e7b47af4bed7c44bfdee019a8..caee2e589f10ab286f51b55045b659e63bdff139 100644 (file)
@@ -101,6 +101,7 @@ class SSLSocket(socket):
                             type=sock.type,
                             proto=sock.proto,
                             fileno=_dup(sock.fileno()))
+            self.settimeout(sock.gettimeout())
             sock.close()
         elif fileno is not None:
             socket.__init__(self, fileno=fileno)
index 403f6bf46c52c2220654dfc0731c6e0bebed1415..7eea4b8d4b0d19578b4433d3afd25c2aa08876aa 100644 (file)
@@ -110,6 +110,15 @@ class BasicTests(unittest.TestCase):
         del ss
         self.assertEqual(wr(), None)
 
+    def test_timeout(self):
+        # Issue #8524: when creating an SSL socket, the timeout of the
+        # original socket should be retained.
+        for timeout in (None, 0.0, 5.0):
+            s = socket.socket(socket.AF_INET)
+            s.settimeout(timeout)
+            ss = ssl.wrap_socket(s)
+            self.assertEqual(timeout, ss.gettimeout())
+
 
 class NetworkedTests(unittest.TestCase):
 
@@ -1262,17 +1271,15 @@ else:
             started.wait()
 
             try:
-                if 0:
-                    # Disabled until #8524 finds a solution
-                    try:
-                        c = socket.socket(socket.AF_INET)
-                        c.settimeout(1.0)
-                        c.connect((host, port))
-                        # Will attempt handshake and time out
-                        self.assertRaisesRegexp(ssl.SSLError, "timed out",
-                                                ssl.wrap_socket, c)
-                    finally:
-                        c.close()
+                try:
+                    c = socket.socket(socket.AF_INET)
+                    c.settimeout(0.2)
+                    c.connect((host, port))
+                    # Will attempt handshake and time out
+                    self.assertRaisesRegexp(ssl.SSLError, "timed out",
+                                            ssl.wrap_socket, c)
+                finally:
+                    c.close()
                 try:
                     c = socket.socket(socket.AF_INET)
                     c = ssl.wrap_socket(c)
index df89d37dff81f471a8c227e78dbda45143b75a30..dd02c3d1bdd3edb033e45b59b78135b3cc4cfa68 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #8524: When creating an SSL socket, the timeout value of the
+  original socket wasn't retained (instead, a socket with a positive timeout
+  would be turned into a non-blocking SSL socket).
+
 - Issue #5103: SSL handshake would ignore the socket timeout and block
   indefinitely if the other end didn't respond.