Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
xep_0199 ping now uses scheduler instead of dedicated thread
  • Loading branch information
fritzy committed Nov 17, 2010
1 parent b73a859 commit b8f40eb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sleekxmpp/plugins/xep_0199.py
Expand Up @@ -21,7 +21,6 @@ def plugin_init(self):
self.description = "XMPP Ping"
self.xep = "0199"
self.xmpp.add_handler("<iq type='get' xmlns='%s'><ping xmlns='urn:xmpp:ping'/></iq>" % self.xmpp.default_ns, self.handler_ping, name='XMPP Ping')
self.running = False
if self.config.get('keepalive', True):
self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)

Expand All @@ -30,12 +29,13 @@ def post_init(self):
self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:ping')

def handler_pingserver(self, xml):
if not self.running:
time.sleep(self.config.get('frequency', 300))
while self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is not False:
time.sleep(self.config.get('frequency', 300))
self.xmpp.schedule("xep-0119 ping", float(self.config.get('frequency', 300)), self.scheduled_ping, repeat=True)

def scheduled_ping(self):
log.debug("pinging...")
if self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is False:
log.debug("Did not recieve ping back in time. Requesting Reconnect.")
self.xmpp.disconnect(reconnect=True)
self.xmpp.reconnect()

def handler_ping(self, xml):
iq = self.xmpp.makeIqResult(xml.get('id', 'unknown'))
Expand Down

0 comments on commit b8f40eb

Please sign in to comment.