From 60dfda48e0819a0137da933da30ba86a80dc1e25 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 26 Apr 2020 15:14:13 +0100 Subject: [PATCH] ping_sent doesn't have to be global --- ircrobots/server.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ircrobots/server.py b/ircrobots/server.py index ea104aa..c8e9246 100644 --- a/ircrobots/server.py +++ b/ircrobots/server.py @@ -43,7 +43,6 @@ class Server(IServer): self.sasl_state = SASLResult.NONE self.last_read = -1.0 - self._ping_sent = False self._sent_count: int = 0 self._write_queue: PriorityQueue[SentLine] = PriorityQueue() @@ -178,21 +177,21 @@ class Server(IServer): if self._read_queue: both = self._read_queue.popleft() else: + ping_sent = False while True: - try: async with timeout(PING_TIMEOUT): data = await self._reader.read(1024) except asyncio.exceptions.TimeoutError: - if self._ping_sent: + if ping_sent: data = b"" # empty data means the socket disconnected else: - self._ping_sent = True + ping_sent = True await self.send(build("PING", ["hello"])) continue self.last_read = monotonic() - self._ping_sent = False + ping_sent = False try: lines = self.recv(data)