summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sleekxmpp/clientxmpp.py7
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py21
2 files changed, 21 insertions, 7 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py
index 004037f2..2501f5d3 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -254,13 +254,6 @@ class ClientXMPP(BaseXMPP):
self.bindfail = False
self.features = set()
- def session_timeout():
- if not self.session_started_event.isSet():
- log.debug("Session start has taken more than 15 seconds")
- self.disconnect(reconnect=self.auto_reconnect)
-
- self.schedule("session timeout checker", 15, session_timeout)
-
def _handle_stream_features(self, features):
"""
Process the received stream features.
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.