summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-25 15:11:26 -0700
committerLance Stout <lancestout@gmail.com>2011-08-25 15:40:13 -0700
commit2162d6042e7eef953a957c0bcf81e65a66a963d4 (patch)
tree27f6c3e560b15a4af91bd29762093d49c8b06f36 /sleekxmpp/xmlstream/xmlstream.py
parentb8a4ffece9d176b4b9a594681fa58668f2cad42f (diff)
downloadslixmpp-2162d6042e7eef953a957c0bcf81e65a66a963d4.tar.gz
slixmpp-2162d6042e7eef953a957c0bcf81e65a66a963d4.tar.bz2
slixmpp-2162d6042e7eef953a957c0bcf81e65a66a963d4.tar.xz
slixmpp-2162d6042e7eef953a957c0bcf81e65a66a963d4.zip
Session timeout now defaults to 45sec, but can be adjusted.
e.g. self.session_timeout = 15 It is also managed by XMLStream instead of ClientXMPP now.
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index c886c3bd..a079cce3 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -211,6 +211,7 @@ class XMLStream(object):
self.stream_end_event = threading.Event()
self.stream_end_event.set()
self.session_started_event = threading.Event()
+ self.session_timeout = 45
self.event_queue = queue.Queue()
self.send_queue = queue.Queue()
@@ -232,6 +233,8 @@ class XMLStream(object):
self.is_client = False
self.dns_answers = []
+ self.add_event_handler('connected', self._handle_connected)
+
def use_signals(self, signals=None):
"""
Register signal handlers for SIGHUP and SIGTERM, if possible,
@@ -337,6 +340,7 @@ class XMLStream(object):
return connected
def _connect(self):
+ self.scheduler.remove('Session timeout check')
self.stop.clear()
if self.default_domain:
self.address = self.pick_dns_answer(self.default_domain,
@@ -446,6 +450,23 @@ class XMLStream(object):
serr.errno, serr.strerror))
return False
+ def _handle_connected(self, event=None):
+ """
+ Add check to ensure that a session is established within
+ a reasonable amount of time.
+ """
+
+ def _handle_session_timeout():
+ if not self.session_started_event.isSet():
+ log.debug("Session start has taken more " + \
+ "than %d seconds" % self.session_timeout)
+ self.disconnect(reconnect=self.auto_reconnect)
+
+ self.schedule("Session timeout check",
+ self.session_timeout,
+ _handle_session_timeout)
+
+
def disconnect(self, reconnect=False, wait=False):
"""
Terminate processing and close the XML streams.