Message117329
Here's a rewriting attempt (not tested).
Now that I look at it I must say it's quite ugly, so I don't think we should follow this road.
An alternative I see is to return None in case of errors occurring on accept() and make this very clear in doc.
Other than accept(), doc should explicitly show how to use handle_accept() in general, which would end up looking like this:
class SomeServer(asyncore.dispatcher):
...
def handle_accept():
conn = self.accept()
if conn is None:
return
else:
sock, addr = conn
...
...
A completely different approach could be to provide a new "TCPServer" class which deprecates direct accept() method usage. Something like this:
class TCPServer(asyncore.dispatcher):
def __init__(self, ip, port, handler, interface='', map=None):
asyncore.dispatcher.__init__(self, map=map)
self.create_socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
self.bind((ip, port))
self.listen(5)
self.handler = handler
def handle_accept(self):
try:
sock, addr = self.accept()
except TypeError:
return
except socket.error, err:
if err[0] != errno.ECONNABORTED:
raise
return
else:
if addr == None:
return
handler = self.handler(conn, self._map)
def writable(self):
return 0
...but for some reason I don't like it either. Point is asyncore API design is fundamentally wrong and there's nothing we can do about it unless we break backward compatibility or a brand new "asyncore2" module is written. |
|
Date |
User |
Action |
Args |
2010-09-24 20:15:56 | giampaolo.rodola | set | recipients:
+ giampaolo.rodola, josiahcarlson, pitrou, matejcik, dmalcolm, santoso.wijaya, BreamoreBoy |
2010-09-24 20:15:55 | giampaolo.rodola | set | messageid: <1285359355.1.0.991060533957.issue6706@psf.upfronthosting.co.za> |
2010-09-24 20:15:53 | giampaolo.rodola | link | issue6706 messages |
2010-09-24 20:15:52 | giampaolo.rodola | create | |
|