From c1d9da8ef8c9aaf0c5e77a1f2aee5ff76a076cf4 Mon Sep 17 00:00:00 2001 From: Jordyn Date: Sat, 14 Mar 2026 03:47:00 -0500 Subject: [PATCH] Improve ping support to avoid ping timeouts Specifically the ping is moved to the message throttling code so that every 10th message triggers a ping. This also allows for me to remove the multiple ping handlers. --- main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 5ff6006..30a9662 100755 --- a/main.py +++ b/main.py @@ -63,7 +63,9 @@ class Server(): def die(self, msg = "Python3 Server() outta here!"): print("[SERVER/MAINTHREAD] Sending PART and QUIT") # Part all of our channels with a cool message, then quit - self._msg_q.put(f"PART {self.channel} : {msg}\r\n".encode()) + for channel in self.channels: + self._msg_q.put(f"PART {channel} : {msg}\r\n".encode()) + self._msg_q.put(f"QUIT : {msg}\r\n".encode()) print("[SERVER/MAINTHREAD] Signaling threads to quit!") @@ -79,6 +81,8 @@ class Server(): print(f"[SENDTHREAD] Sleeping for {self._msg_time} seconds on message count {self._msg_count}") time.sleep(self._msg_time) if self._msg_count == 10: + print("[SENDTHREAD] Sending ping on 10th message!") + self.sock.send(f"PING :{ip}\r\n".encode()) self._msg_count = 0 # Grab message and send it @@ -86,8 +90,7 @@ class Server(): msg = self._msg_q.get(timeout = 60) except queue.Empty: # So the thread signaler works - print("[SENDTHREAD] Timeout occurred waiting on queue... sending ping!") - self.sock.send(f"PING :{ip}\r\n".encode()) + continue print(f"[SENDTHREAD] Sending message: {msg}") try: @@ -121,10 +124,7 @@ class Server(): print("[RECVTHREAD] Message: {data}") continue except socket.timeout: - # Instead of using another thread, I just use a socket timeout to send pings - # Kills two birds with one stone as we can't wait forever due to threading Events - print("[RECVTHREAD] Timeout occurred waiting on server messages... sending ping!") - self.sock.send(f"PING :{ip}\r\n".encode()) + # So threading Events work continue # Handle IRC messages @@ -288,7 +288,7 @@ class Server(): # Calculate maximum message size # 512 bytes is max IRC message with