From: Ben Darnell Date: Sun, 4 Aug 2013 22:35:50 +0000 (-0400) Subject: Less crude fix for #855: only do anything for already-connected sockets. X-Git-Tag: v3.2.0b1~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1037f0830a38f4e5d0ac93d624b6d7f64a72010a;p=thirdparty%2Ftornado.git Less crude fix for #855: only do anything for already-connected sockets. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index bc4ca9287..6bdc6397b 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -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()