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:
parent
dce050aac5
commit
72dca06626
3 changed files with 10 additions and 2 deletions
|
@ -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", [])
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue