diff --git a/modules/signals.py b/modules/signals.py index 627becfe..9bf2c9a8 100644 --- a/modules/signals.py +++ b/modules/signals.py @@ -21,7 +21,8 @@ class Module(ModuleManager.BaseModule): server.send_quit(reason) self.bot.trigger() - self.bot.running = False + self.events.on("writebuffer.empty").hook( + lambda event: self.bot.disconnect(event["server"])) def SIGUSR1(self, signum, frame): self.bot.log.info("Reloading config file", []) diff --git a/src/IRCBot.py b/src/IRCBot.py index 16ee3007..62594404 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -157,6 +157,9 @@ class Bot(object): def run(self): while self.running: + if not self.servers: + break + events = self.poll.poll(self.get_poll_timeout()) self.lock.acquire() self._timers.call() @@ -189,7 +192,8 @@ class Bot(object): sock.parse_data(piece) elif event & select.EPOLLOUT: sock._send() - self.register_read(sock) + if sock.fileno() in self.servers: + self.register_read(sock) elif event & select.EPULLHUP: print("hangup") sock.disconnect() diff --git a/src/IRCServer.py b/src/IRCServer.py index c52c32d6..2379ecc2 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -299,6 +299,9 @@ class Server(IRCObject.Object): self.bytes_written += bytes_written self.write_buffer = self.write_buffer[bytes_written:] + if not self.waiting_send(): + self.events.on("writebuffer.empty").call(server=self) + now = time.monotonic() self.recent_sends.append(now) self.last_send = now