diff options
| author | 2018-08-29 14:33:27 +0100 | |
|---|---|---|
| committer | 2018-08-29 14:33:27 +0100 | |
| commit | 43ab3cbd102b365439b271f23bfa45da3cc03ab8 (patch) | |
| tree | ef01538da82f611e89cec8e4535cb607a636bc49 /IRCServer.py | |
| parent | Forgot to add IRCBuffer.py when I renamed it from IRCLog.py. oops. (diff) | |
| signature | ||
Factor ping interval and ping timeout in to the main loop's minimum interval
Diffstat (limited to 'IRCServer.py')
| -rw-r--r-- | IRCServer.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/IRCServer.py b/IRCServer.py index 46dedbb7..8d4e4b64 100644 --- a/IRCServer.py +++ b/IRCServer.py @@ -1,9 +1,12 @@ import collections, socket, ssl, sys, time import IRCChannel, IRCUser -OUR_TLS_PROTOCOL = ssl.PROTOCOL_SSLv23 THROTTLE_LINES = 4 THROTTLE_SECONDS = 1 +READ_TIMEOUT_SECONDS = 120 +PING_INTERVAL_SECONDS = 30 + +OUR_TLS_PROTOCOL = ssl.PROTOCOL_SSLv23 if hasattr(ssl, "PROTOCOL_TLS"): OUR_TLS_PROTOCOL = ssl.PROTOCOL_TLS @@ -38,7 +41,7 @@ class Server(object): self.channel_modes = [] self.channel_types = [] - self.last_read = None + self.last_read = time.monotonic() self.last_send = None self.attempted_join = {} @@ -204,6 +207,19 @@ class Server(object): self.last_read = time.monotonic() self.ping_sent = False return decoded_lines + + def until_next_ping(self): + return max(0, (self.last_read+PING_INTERVAL_SECONDS + )-time.monotonic()) + def ping_due(self): + return self.until_next_ping() == 0 + + def until_read_timeout(self): + return max(0, (self.last_read+READ_TIMEOUT_SECONDS + )-time.monotonic()) + def read_timed_out(self): + return self.until_read_timeout == 0 + def send(self, data): encoded = data.split("\n")[0].strip("\r").encode("utf8") if len(encoded) > 450: |
