From 75f5d263fdb537696063ee7afcdf3f24d7ec8113 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Thu, 1 Nov 2007 20:35:24 -0800 Subject: [PATCH] add code to handle resending the notifys out every seven minutes.. This should prevent the DSM-520 from saying we've disappeared... 7 minutes means 4 sends before the 30 minutes max-age hits and is a pretty good compromise, though we do send out five notifies each time... [git-p4: depot-paths = "//depot/": change = 1087] --- SSDP.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SSDP.py b/SSDP.py index 728fb87..bcff7ee 100644 --- a/SSDP.py +++ b/SSDP.py @@ -15,7 +15,7 @@ import string from twisted.python import log from twisted.internet.protocol import DatagramProtocol -from twisted.internet import reactor +from twisted.internet import reactor, task # TODO: Is there a better way of hooking the SSDPServer into a reactor # without having to know the default SSDP port and multicast address? @@ -37,12 +37,22 @@ class SSDPServer(DatagramProtocol): stdheaders = [ ('Server', 'Twisted, UPnP/1.0, python-upnp'), ] elements = {} known = {} + tasks = [] def doStop(self): '''Make sure we send out the byebye notifications.''' - for st in self.known: + while True: + try: + t = self.tasks.pop() + t.stop() + except IndexError: + break + + for st in self.known.keys(): self.doByebye(st) + del self.known[st] + DatagramProtocol.doStop(self) def datagramReceived(self, data, (host, port)): @@ -113,6 +123,10 @@ class SSDPServer(DatagramProtocol): self.known[st]['CACHE-CONTROL'] = 'max-age=1800' self.doNotify(st) + t = task.LoopingCall(lambda: self.doNotify(st)) + t.start(7 * 60) + self.tasks.append(t) + def doByebye(self, st): """Do byebye"""