check if we should enable write throttling before writing, clear _recent_sends

when we turn on throttling and only "turn on" throttling once
This commit is contained in:
jesopo 2019-06-01 22:28:57 +01:00
parent b84d133500
commit 20c027fd0b

View file

@ -124,6 +124,12 @@ class Socket(IRCObject.Object):
def _send(self) -> typing.List[IRCLine.ParsedLine]: def _send(self) -> typing.List[IRCLine.ParsedLine]:
sent_lines = [] 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() throttle_space = self.throttle_space()
if throttle_space: if throttle_space:
to_buffer = self._queued_lines[: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:] 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 self.bytes_written += bytes_written_i
now = time.monotonic() now = time.monotonic()