From d8ecf68c5805d608f222965bb53d111578bfdf5a Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sun, 9 Feb 2014 12:53:07 +0100 Subject: close socket if IRC connection closes Phenny has some restart logic, if the asyncore loop ends. But for this all open sockets have to be closed. Our new socket keeps the loop running even without a connection to the IRC. So we need to close our socket, if the socket of phenny closes. (It is a bit monkey patching, becuase phenny does not have any hooks.) --- socket_notify.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/socket_notify.py b/socket_notify.py index 6a56e71..0ab5dd6 100644 --- a/socket_notify.py +++ b/socket_notify.py @@ -35,6 +35,8 @@ class Monitor(asyncore.dispatcher): def __init__(self, path, phenny): asyncore.dispatcher.__init__(self) self.phenny = phenny + self.phenny._orig_close = self.phenny.close + self.phenny.close = (lambda: self._phenny_close()) self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) try: @@ -52,7 +54,11 @@ class Monitor(asyncore.dispatcher): os.umask(old_mask) self.listen(5) - + + def _phenny_close(self): + self.close() + self.phenny._orig_close() + def handle_accept(self): pair = self.accept() if pair is not None: -- cgit v1.2.3-1-g7c22