summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-09-01 16:24:09 -0700
committerLance Stout <lancestout@gmail.com>2011-09-01 16:24:09 -0700
commit6f72c05ebf6f464c59f6d647b5dd0c2f8d57744a (patch)
tree35fd10b2245e83c3e5b6fb2b32c2aded11028ea8 /sleekxmpp/xmlstream/xmlstream.py
parent20cacc84badca3d11e572e221b759797f6ade51b (diff)
downloadslixmpp-6f72c05ebf6f464c59f6d647b5dd0c2f8d57744a.tar.gz
slixmpp-6f72c05ebf6f464c59f6d647b5dd0c2f8d57744a.tar.bz2
slixmpp-6f72c05ebf6f464c59f6d647b5dd0c2f8d57744a.tar.xz
slixmpp-6f72c05ebf6f464c59f6d647b5dd0c2f8d57744a.zip
Add whitespace keepalive option.sleek-1.0-RC21.0-RC2
May be disabled by setting: self.whitespace_keepalive = False The keepalive interval can be adjusted using: self.whitespace_keepalive_interval = 300 The default interval is 5min.
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 3175d92b..10f4a05f 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -212,6 +212,9 @@ class XMLStream(object):
self.stream_header = "<stream>"
self.stream_footer = "</stream>"
+ self.whitespace_keepalive = True
+ self.whitespace_keepalive_interval = 300
+
self.stop = threading.Event()
self.stream_end_event = threading.Event()
self.stream_end_event.set()
@@ -238,6 +241,8 @@ class XMLStream(object):
self.dns_answers = []
self.add_event_handler('connected', self._handle_connected)
+ self.add_event_handler('session_start', self._start_keepalive)
+ self.add_event_handler('session_end', self._end_keepalive)
def use_signals(self, signals=None):
"""
@@ -615,6 +620,30 @@ class XMLStream(object):
log.warning("Tried to enable TLS, but ssl module not found.")
return False
+ def _start_keepalive(self, event):
+ """
+ Begin sending whitespace periodically to keep the connection alive.
+
+ May be disabled by setting:
+ self.whitespace_keepalive = False
+
+ The keepalive interval can be set using:
+ self.whitespace_keepalive_interval = 300
+ """
+
+ def send_keepalive():
+ if self.send_queue.empty():
+ self.send_raw(' ')
+
+ self.schedule('Whitespace Keepalive',
+ self.whitespace_keepalive_interval,
+ send_keepalive,
+ repeat=True)
+
+ def _end_keepalive(self, event):
+ """Stop sending whitespace keepalives"""
+ self.scheduler.remove('Whitespace Keepalive')
+
def start_stream_handler(self, xml):
"""
Perform any initialization actions, such as handshakes, once the