@@ -15,7 +15,7 @@ import string
from twisted.python import log
from twisted.python import log
from twisted.internet.protocol import DatagramProtocol
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
# TODO: Is there a better way of hooking the SSDPServer into a reactor
# without having to know the default SSDP port and multicast address?
# 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'), ]
stdheaders = [ ('Server', 'Twisted, UPnP/1.0, python-upnp'), ]
elements = {}
elements = {}
known = {}
known = {}
tasks = []
def doStop(self):
def doStop(self):
'''Make sure we send out the byebye notifications.'''
'''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)
self.doByebye(st)
del self.known[st]
DatagramProtocol.doStop(self)
DatagramProtocol.doStop(self)
def datagramReceived(self, data, (host, port)):
def datagramReceived(self, data, (host, port)):
@@ -113,6 +123,10 @@ class SSDPServer(DatagramProtocol):
self.known[st]['CACHE-CONTROL'] = 'max-age=1800'
self.known[st]['CACHE-CONTROL'] = 'max-age=1800'
self.doNotify(st)
self.doNotify(st)
t = task.LoopingCall(lambda: self.doNotify(st))
t.start(7 * 60)
self.tasks.append(t)
def doByebye(self, st):
def doByebye(self, st):
"""Do byebye"""
"""Do byebye"""