Browse Source

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]
replace/b43bf02ddeddd088c0e6b94974ca1a46562eb3db
John-Mark Gurney 17 years ago
parent
commit
75f5d263fd
1 changed files with 16 additions and 2 deletions
  1. +16
    -2
      SSDP.py

+ 16
- 2
SSDP.py View File

@@ -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"""



Loading…
Cancel
Save