From 4bb7474e79870d49489e63e73a3089fe61b47d96 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Mon, 22 Aug 2022 19:42:53 +1200 Subject: [PATCH] Fix more bugs --- miniirc.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/miniirc.py b/miniirc.py index 3ecf8ab..b4edd53 100755 --- a/miniirc.py +++ b/miniirc.py @@ -288,8 +288,9 @@ def quote(self, *msg, force=None, tags=None): self._send_lock.acquire() sent_bytes = 0 try: # Apparently try/finally is faster than "with". - while sent_bytes < len(msg): + while True: try: + # Attempt to send to the socket sent_bytes += self.sock.send(msg[sent_bytes:]) except ssl.SSLWantReadError: # Wait for the socket to become ready again @@ -297,9 +298,17 @@ def quote(self, *msg, force=None, tags=None): (self.sock,), (), (self.sock,), self.ping_timeout or self.ping_interval ) + continue except (BlockingIOError, ssl.SSLWantWriteError): - select.select((), (self.sock,), (self.sock,), - self.ping_timeout or self.ping_interval) + pass + else: + # Break if enough data has been written + if sent_bytes >= len(msg): + break + + # Otherwise wait for the socket to become writable + select.select((), (self.sock,), (self.sock,), + self.ping_timeout or self.ping_interval) except (AttributeError, BrokenPipeError, socket.timeout): # TODO: Consider not silently ignoring timeouts if force: