A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-November/075417.html below:

[Python-Dev] ssl module integration with asyncore

[Python-Dev] ssl module integration with asyncoreBill Janssen janssen at parc.com
Thu Nov 29 00:26:24 CET 2007
> I tried to write a simple asyncore-based server code, then I used a
> simple client to establish a connection with it.
> Once the client is connected server raises the following exception:

I think this is a bug.  Thanks!

The issue is that the internal call to do_handshake() doesn't handle
non-blocking sockets properly.

You can work around the bug like this:

--- snippet ---
import asyncore, asynchat, socket, ssl, select

class Handler(asyncore.dispatcher):

    def __init__(self, conn):
        asyncore.dispatcher.__init__(self, conn)
        self.socket = ssl.wrap_socket(conn, server_side=True,
                                      certfile='keycert.pem',
                                      do_handshake_on_connect=False)
        while True:
            try:
                self.socket.do_handshake()
                break
            except ssl.SSLError, err:
                if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                    select.select([self.socket], [], [])
                elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                    select.select([], [self.socket], [])
                else:
                    raise
        self.send('hi there')
--- /snippet ---

Bill

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4