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()