summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2014-02-09 12:53:07 +0100
committerAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2014-02-09 12:55:59 +0100
commitd8ecf68c5805d608f222965bb53d111578bfdf5a (patch)
tree47fc2906d9c1d920f74d19aee729757c28da976b
parenta2223374bf0e10bfc8ebd2cd3374e1bbd5327aac (diff)
downloadsocket-notify-d8ecf68c5805d608f222965bb53d111578bfdf5a.tar.gz
socket-notify-d8ecf68c5805d608f222965bb53d111578bfdf5a.tar.bz2
socket-notify-d8ecf68c5805d608f222965bb53d111578bfdf5a.zip
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.)
-rw-r--r--socket_notify.py8
1 files changed, 7 insertions, 1 deletions
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: