[Python-Dev] ssl module, non-blocking sockets and asyncore integration (original) (raw)
Giampaolo Rodola' gnewsg at gmail.com
Thu Sep 18 00:49:37 CEST 2008
- Previous message: [Python-Dev] ssl module, non-blocking sockets and asyncore integration
- Next message: [Python-Dev] ssl module, non-blocking sockets and asyncore integration
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ok, here's some news, in case they can be of some interest. I managed to write an asyncore disptacher which seems to work. I used my test suite against it and 70 tests passed and 2 failed. The tests failed because at a certain point a call to do_handhsake results in an EOF exception, which is very strange since it is supposed to raise SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE only. I'll keep you updated in case I have some news.
--- Exception ---
File "C:\python26\lib\ssl.py", line 293, in do_handshake self._sslobj.do_handshake() SSLError: [Errno 8] _ssl.c:480: EOF occurred in violation of protocol
--- SSL dispatcher ----
class SSLConnection(asyncore.dispatcher):
def __init__(self):
self.ssl_handshake_pending = False
def do_ssl_handshake(self):
try:
self.socket.do_handshake()
except ssl.SSLError, err:
if err.args[0] == ssl.SSL_ERROR_WANT_READ:
self.ssl_handshake_pending = 'read'
elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
self.ssl_handshake_pending = 'write'
else:
raise
else:
self.ssl_handshake_pending = False
def handle_read_event(self):
if self.ssl_handshake_pending == 'read':
self.do_ssl_handshake()
if not self.ssl_handshake_pending:
asyncore.dispatcher.handle_read_event(self)
else:
asyncore.dispatcher.handle_read_event(self)
def handle_write_event(self):
if self.ssl_handshake_pending == 'write':
self.do_ssl_handshake()
if not self.ssl_handshake_pending:
asyncore.dispatcher.handle_write_event(self)
else:
asyncore.dispatcher.handle_write_event(self)
--- Giampaolo http://code.google.com/p/pyftpdlib/
- Previous message: [Python-Dev] ssl module, non-blocking sockets and asyncore integration
- Next message: [Python-Dev] ssl module, non-blocking sockets and asyncore integration
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]