summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorTom Nichols <tmnichols@gmail.com>2010-07-09 16:06:53 -0400
committerTom Nichols <tmnichols@gmail.com>2010-07-09 16:06:53 -0400
commit3c6b07353dc0243a799e26fed5d08af662600d1e (patch)
tree55d990d145181114b80d1aa8b2bd824fc9418657 /sleekxmpp/xmlstream
parent66c6c21ad83c55246eb1a57d2f2885949db87c1a (diff)
downloadslixmpp-3c6b07353dc0243a799e26fed5d08af662600d1e.tar.gz
slixmpp-3c6b07353dc0243a799e26fed5d08af662600d1e.tar.bz2
slixmpp-3c6b07353dc0243a799e26fed5d08af662600d1e.tar.xz
slixmpp-3c6b07353dc0243a799e26fed5d08af662600d1e.zip
added keepalive to send thread
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 00af3d2e..7098e1c1 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -47,6 +47,7 @@ stanza_extensions = {}
RECONNECT_MAX_DELAY = 3600
RECONNECT_QUIESCE_FACTOR = 1.6180339887498948 # Phi
RECONNECT_QUIESCE_JITTER = 0.11962656472 # molar Planck constant times c, joule meter/mole
+DEFAULT_KEEPALIVE = 300 # send a single byte every 5 minutes
class XMLStream(object):
"A connection manager with XML events."
@@ -74,6 +75,9 @@ class XMLStream(object):
self.use_tls = False
self.ca_certs=None
+ self.keep_alive = DEFAULT_KEEPALIVE
+ self._last_sent_time = time.time()
+
self.stream_header = "<stream>"
self.stream_footer = "</stream>"
@@ -290,9 +294,12 @@ class XMLStream(object):
data = self.sendqueue.get(True,5)[1]
logging.debug("SEND: %s" % data)
self.socket.sendall(data.encode('utf-8'))
- except queue.Empty:
-# logging.debug('Nothing on send queue')
- pass
+ self._last_sent_time = time.time()
+ except queue.Empty: # send keep-alive if necessary
+ now = time.time()
+ if self._last_sent_time + self.keep_alive < now:
+ self.socket.sendall(' ')
+ self._last_sent_time = time.time()
except socket.timeout:
# this is to prevent a thread blocked indefinitely
logging.debug('timeout sending packet data')