summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
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.