[New-bugs-announce] [issue12498] asyncore.dispatcher_with_send, disconnection problem + miss-conception

François-Xavier Bourlet report at bugs.python.org
Tue Jul 5 03:55:30 CEST 2011


New submission from François-Xavier Bourlet <bombela at gmail.com>:

Actually the class asyncore.dispatcher_with_send do not handle properly disconnection. When the endpoint shutdown his sending part of the socket, but keep the socket open in reading, the current implementation of dispatcher_with_send will close the socket without sending pending data.

Adding this method to the class fix the problem:

    def handle_close(self):
        if not self.writable():
            dispatcher.close()

Note also that this class try to initiate a send even if the socket is maybe not ready for writing:

Here's a simple fix:
    def send(self, data):
        if self.debug:
            self.log_info('sending %s' % repr(data))
        self.out_buffer = self.out_buffer + data
-       self.initiate_send()

Last but not last, the buffer size of each socket send are way to small (512, a third of an usual TCP frame). Here's the code with a bumped value:

    def initiate_send(self):
        num_sent = 0
-       num_sent = dispatcher.send(self, self.out_buffer[:512])
+       num_sent = dispatcher.send(self, self.out_buffer[:8192])
        self.out_buffer = self.out_buffer[num_sent:]

Thanks for reading,

----------
components: IO
messages: 139821
nosy: François-Xavier.Bourlet
priority: normal
severity: normal
status: open
title: asyncore.dispatcher_with_send, disconnection problem + miss-conception
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12498>
_______________________________________


More information about the New-bugs-announce mailing list