diff options
author | Nathan Fritz <fritzy@netflint.net> | 2011-08-18 00:35:37 -0700 |
---|---|---|
committer | Nathan Fritz <fritzy@netflint.net> | 2011-08-18 00:35:37 -0700 |
commit | 4ea22ff69bac4b619b1eeb918c67a209f6e953ee (patch) | |
tree | cc4a245ea03429d59b192cb3f79b3bee95343ba8 /sleekxmpp/plugins/xep_0199/ping.py | |
parent | 3853898ab36fa1a74b5d9d5ea3070c3e8e1bc0f2 (diff) | |
parent | 7d8aa4157bc7a602243996a45268b172629a6ae3 (diff) | |
download | slixmpp-4ea22ff69bac4b619b1eeb918c67a209f6e953ee.tar.gz slixmpp-4ea22ff69bac4b619b1eeb918c67a209f6e953ee.tar.bz2 slixmpp-4ea22ff69bac4b619b1eeb918c67a209f6e953ee.tar.xz slixmpp-4ea22ff69bac4b619b1eeb918c67a209f6e953ee.zip |
Merge branch 'develop' of github.com:fritzy/SleekXMPP into develop
Diffstat (limited to 'sleekxmpp/plugins/xep_0199/ping.py')
-rw-r--r-- | sleekxmpp/plugins/xep_0199/ping.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sleekxmpp/plugins/xep_0199/ping.py b/sleekxmpp/plugins/xep_0199/ping.py index 0fa22f8a..b0304b09 100644 --- a/sleekxmpp/plugins/xep_0199/ping.py +++ b/sleekxmpp/plugins/xep_0199/ping.py @@ -11,6 +11,7 @@ import logging import sleekxmpp from sleekxmpp import Iq +from sleekxmpp.exceptions import IqError, IqTimeout from sleekxmpp.xmlstream import register_stanza_plugin from sleekxmpp.xmlstream.matcher import StanzaPath from sleekxmpp.xmlstream.handler import Callback @@ -89,8 +90,13 @@ class xep_0199(base_plugin): def scheduled_ping(): """Send ping request to the server.""" log.debug("Pinging...") - resp = self.send_ping(self.xmpp.boundjid.host, self.timeout) - if resp is None or resp is False: + try: + self.send_ping(self.xmpp.boundjid.host, self.timeout) + except IqError: + log.debug("Ping response was an error." + \ + "Requesting Reconnect.") + self.xmpp.reconnect() + except IqTimeout: log.debug("Did not recieve ping back in time." + \ "Requesting Reconnect.") self.xmpp.reconnect() @@ -142,9 +148,14 @@ class xep_0199(base_plugin): iq.enable('ping') start_time = time.clock() - resp = iq.send(block=block, - timeout=timeout, - callback=callback) + + try: + resp = iq.send(block=block, + timeout=timeout, + callback=callback) + except IqError as err: + resp = err.iq + end_time = time.clock() delay = end_time - start_time @@ -152,9 +163,6 @@ class xep_0199(base_plugin): if not block: return None - if not resp or resp['type'] == 'error': - return False - log.debug("Pong: %s %f" % (jid, delay)) return delay |