aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-05-31 15:49:34 +0100
committerGravatar jesopo2019-05-31 15:49:34 +0100
commitdc284bab4a1c3fd533c0e0c8c67f2f97ee1c79c2 (patch)
treeb87f60434062bc95deba7b90546b86ce918155d2 /src
parentMore explicitly require `throttle_done()` only for `_queued_lines` (diff)
signature
Only enable write throttling when _write_buffer is empty
closes #59
Diffstat (limited to 'src')
-rw-r--r--src/IRCSocket.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/IRCSocket.py b/src/IRCSocket.py
index 642e1968..b93087eb 100644
--- a/src/IRCSocket.py
+++ b/src/IRCSocket.py
@@ -27,13 +27,15 @@ class Socket(IRCObject.Object):
self._write_buffer = b""
self._queued_lines = [] # type: typing.List[IRCLine.SentLine]
self._buffered_lines = [] # type: typing.List[IRCLine.SentLine]
- self._write_throttling = False
self._read_buffer = b""
self._recent_sends = [] # type: typing.List[float]
self.cached_fileno = None # type: typing.Optional[int]
self.bytes_written = 0
self.bytes_read = 0
+ self._write_throttling = False
+ self._throttle_when_empty = False
+
self.last_read = time.monotonic()
self.last_send = None # type: typing.Optional[float]
@@ -140,6 +142,9 @@ 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()
@@ -185,5 +190,5 @@ class Socket(IRCObject.Object):
time_left = time_left-time.monotonic()
return time_left
- def set_write_throttling(self, is_on: bool):
- self._write_throttling = is_on
+ def enable_write_throttle(self):
+ self._throttle_when_empty = True