]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Less crude fix for #855: only do anything for already-connected sockets.
authorBen Darnell <ben@bendarnell.com>
Sun, 4 Aug 2013 22:35:50 +0000 (18:35 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 4 Aug 2013 22:35:50 +0000 (18:35 -0400)
tornado/iostream.py

index bc4ca9287ed21f848013b3a81c11378968f8e6b1..6bdc6397baa4269d57971179a430195852ef9e1c 100644 (file)
@@ -801,10 +801,17 @@ class SSLIOStream(IOStream):
         self._handshake_writing = False
         self._ssl_connect_callback = None
         self._server_hostname = None
-        self._initiate_handshake()
 
-    def _initiate_handshake(self):
-        self._add_io_state(self.io_loop.READ | self.io_loop.WRITE)
+        # If the socket is already connected, attempt to start the handshake.
+        try:
+            self.socket.getpeername()
+        except socket.error:
+            pass
+        else:
+            # Indirectly start the handshake, which will run on the next
+            # IOLoop iteration and then the real IO state will be set in
+            # _handle_events.
+            self._add_io_state(self.io_loop.WRITE)
 
     def reading(self):
         return self._handshake_reading or super(SSLIOStream, self).reading()