'Perform SSL handshaking, copied from python stdlib test_ssl.py.'

def _do_ssl_handshake(self):

    if (not self.DO_HANDSHAKE):
        return
    while True:
        try:
            self.socket.do_handshake()
            break
        except ssl.SSLError as err:
            if (err.args[0] == ssl.SSL_ERROR_WANT_READ):
                self.event_state = self.READ
            elif (err.args[0] == ssl.SSL_ERROR_WANT_WRITE):
                self.event_state = self.WRITE
            else:
                raise
            self._manage_event_state()
