aboutsummaryrefslogtreecommitdiff
path: root/src/IRCSocket.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/IRCSocket.py')
-rw-r--r--src/IRCSocket.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/IRCSocket.py b/src/IRCSocket.py
index 82c736ee..3a38e8e8 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]
@@ -58,6 +60,7 @@ class Socket(IRCObject.Object):
bindhost = (self._bindhost, 0)
self._socket = socket.create_connection((self._hostname, self._port),
5.0, bindhost)
+ self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
if self._tls:
self._tls_wrap()
@@ -121,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]
@@ -152,6 +161,8 @@ class Socket(IRCObject.Object):
def waiting_send(self) -> bool:
return bool(len(self._write_buffer)) or bool(len(self._queued_lines))
+ def waiting_immediate_send(self) -> bool:
+ return bool(len(self._write_buffer))
def throttle_done(self) -> bool:
return self.send_throttle_timeout() == 0
@@ -182,5 +193,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