diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -535,6 +535,7 @@ num_sent = 0 num_sent = dispatcher.send(self, self.out_buffer[:512]) self.out_buffer = self.out_buffer[num_sent:] + return num_sent def handle_write(self): self.initiate_send() @@ -548,6 +549,15 @@ self.out_buffer = self.out_buffer + data self.initiate_send() + def handle_close(self): + if not self.closing: + self.closing = True + # try to drain the output buffer + while self.writable() and self.initiate_send() > 0: + pass + self.close() + + # --------------------------------------------------------------------------- # used for debugging. # ---------------------------------------------------------------------------