Add a way to catch when a writebuffer is emptied so we can e.g. assure a QUIT is

sent before shutting down the bot
This commit is contained in:
jesopo 2018-11-27 11:56:03 +00:00
parent dce050aac5
commit 72dca06626
3 changed files with 10 additions and 2 deletions

View file

@ -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", [])

View file

@ -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()

View file

@ -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