This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author giampaolo.rodola
Recipients BreamoreBoy, dmalcolm, giampaolo.rodola, josiahcarlson, matejcik, pitrou, santoso.wijaya
Date 2010-09-24.20:15:51
SpamBayes Score 6.836772e-10
Marked as misclassified No
Message-id <1285359355.1.0.991060533957.issue6706@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-09-24 20:15:56giampaolo.rodolasetrecipients: + giampaolo.rodola, josiahcarlson, pitrou, matejcik, dmalcolm, santoso.wijaya, BreamoreBoy
2010-09-24 20:15:55giampaolo.rodolasetmessageid: <1285359355.1.0.991060533957.issue6706@psf.upfronthosting.co.za>
2010-09-24 20:15:53giampaolo.rodolalinkissue6706 messages
2010-09-24 20:15:52giampaolo.rodolacreate