Skip to content
This repository
Browse code

xep_0199 ping now uses scheduler instead of dedicated thread

  • Loading branch information...
commit b8f40eb8431dd0965d6ed3fd61956f4c91729202 1 parent b73a859
Nathan Fritz authored

Showing 1 changed file with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. +6 6 sleekxmpp/plugins/xep_0199.py
12 sleekxmpp/plugins/xep_0199.py
@@ -21,7 +21,6 @@ def plugin_init(self):
21 21 self.description = "XMPP Ping"
22 22 self.xep = "0199"
23 23 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')
24   - self.running = False
25 24 if self.config.get('keepalive', True):
26 25 self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)
27 26
@@ -30,12 +29,13 @@ def post_init(self):
30 29 self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:ping')
31 30
32 31 def handler_pingserver(self, xml):
33   - if not self.running:
34   - time.sleep(self.config.get('frequency', 300))
35   - while self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is not False:
36   - time.sleep(self.config.get('frequency', 300))
  32 + self.xmpp.schedule("xep-0119 ping", float(self.config.get('frequency', 300)), self.scheduled_ping, repeat=True)
  33 +
  34 + def scheduled_ping(self):
  35 + log.debug("pinging...")
  36 + if self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is False:
37 37 log.debug("Did not recieve ping back in time. Requesting Reconnect.")
38   - self.xmpp.disconnect(reconnect=True)
  38 + self.xmpp.reconnect()
39 39
40 40 def handler_ping(self, xml):
41 41 iq = self.xmpp.makeIqResult(xml.get('id', 'unknown'))

0 comments on commit b8f40eb

Please sign in to comment.
Something went wrong with that request. Please try again.