From 20c027fd0bd755ff51ea3a121bcd3b370118e758 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 1 Jun 2019 22:28:57 +0100 Subject: [PATCH] check if we should enable write throttling before writing, clear _recent_sends when we turn on throttling and only "turn on" throttling once --- src/IRCSocket.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/IRCSocket.py b/src/IRCSocket.py index b93087eb..3a38e8e8 100644 --- a/src/IRCSocket.py +++ b/src/IRCSocket.py @@ -124,6 +124,12 @@ class Socket(IRCObject.Object): def _send(self) -> typing.List[IRCLine.ParsedLine]: sent_lines = [] + + if not self._write_buffer and self._throttle_when_empty: + self._throttle_when_empty = False + self._write_throttling = True + self._recent_sends.clear() + throttle_space = self.throttle_space() if throttle_space: to_buffer = self._queued_lines[:throttle_space] @@ -142,9 +148,6 @@ class Socket(IRCObject.Object): self._write_buffer = self._write_buffer[bytes_written_i:] - if not self._write_buffer and self._throttle_when_empty: - self._write_throttling = True - self.bytes_written += bytes_written_i now = time.monotonic()