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.
This commit is contained in:
Lance Stout 2011-08-25 15:11:26 -07:00
parent b8a4ffece9
commit 2162d6042e
2 changed files with 21 additions and 7 deletions

View file

@ -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.

View file

@ -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.