summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-25 15:08:45 -0700
committerLance Stout <lancestout@gmail.com>2011-08-25 15:08:45 -0700
commitb8a4ffece9d176b4b9a594681fa58668f2cad42f (patch)
tree074259ff3b75271bed14b5eac2e331de067533e7 /sleekxmpp
parentd929e0deb2ecc6a4b4da7136cba00cb7492573b7 (diff)
downloadslixmpp-b8a4ffece9d176b4b9a594681fa58668f2cad42f.tar.gz
slixmpp-b8a4ffece9d176b4b9a594681fa58668f2cad42f.tar.bz2
slixmpp-b8a4ffece9d176b4b9a594681fa58668f2cad42f.tar.xz
slixmpp-b8a4ffece9d176b4b9a594681fa58668f2cad42f.zip
Handle sending stanzas in chunks if the socket has poor performance.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/test/livesocket.py2
-rw-r--r--sleekxmpp/test/mocksocket.py1
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py36
3 files changed, 26 insertions, 13 deletions
diff --git a/sleekxmpp/test/livesocket.py b/sleekxmpp/test/livesocket.py
index 7dd4693c..80d63307 100644
--- a/sleekxmpp/test/livesocket.py
+++ b/sleekxmpp/test/livesocket.py
@@ -138,7 +138,7 @@ class TestLiveSocket(object):
"""
with self.send_queue_lock:
self.send_queue.put(data)
- self.socket.send(data)
+ return self.socket.send(data)
# ------------------------------------------------------------------
# File Socket
diff --git a/sleekxmpp/test/mocksocket.py b/sleekxmpp/test/mocksocket.py
index a2af8d6b..0920b7ea 100644
--- a/sleekxmpp/test/mocksocket.py
+++ b/sleekxmpp/test/mocksocket.py
@@ -121,6 +121,7 @@ class TestSocket(object):
if self.disconnected:
raise socket.error
self.send_queue.put(data)
+ return len(data)
# ------------------------------------------------------------------
# File Socket
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 3ce278f0..c886c3bd 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -915,7 +915,15 @@ class XMLStream(object):
if now:
log.debug("SEND (IMMED): %s" % data)
try:
- self.socket.send(data.encode('utf-8'))
+ data = data.encode('utf-8')
+ total = len(data)
+ sent = 0
+ count = 0
+ while sent < total and not self.stop.is_set():
+ sent += self.socket.send(data[sent:])
+ count += 1
+ if count > 1:
+ log.debug('SENT: %d chunks' % count)
except Socket.error as serr:
self.event('socket_error', serr)
log.warning("Failed to send %s" % data)
@@ -1222,7 +1230,7 @@ class XMLStream(object):
Extract stanzas from the send queue and send them on the stream.
"""
try:
- while not self.stop.isSet():
+ while not self.stop.is_set():
self.session_started_event.wait()
if self.__failed_send_stanza is not None:
data = self.__failed_send_stanza
@@ -1234,22 +1242,26 @@ class XMLStream(object):
continue
log.debug("SEND: %s" % data)
try:
- self.socket.send(data.encode('utf-8'))
+ enc_data = data.encode('utf-8')
+ total = len(enc_data)
+ sent = 0
+ count = 0
+ while sent < total and not self.stop.is_set():
+ sent += self.socket.send(enc_data[sent:])
+ count += 1
+ if count > 1:
+ log.debug('SENT: %d chunks' % count)
self.send_queue.task_done()
except Socket.error as serr:
self.event('socket_error', serr)
log.warning("Failed to send %s" % data)
self.__failed_send_stanza = data
self.disconnect(self.auto_reconnect)
- except KeyboardInterrupt:
- log.debug("Keyboard Escape Detected in _send_thread")
- self.event('killed', direct=True)
- self.disconnect()
- return
- except SystemExit:
- self.disconnect()
- self.event_queue.put(('quit', None, None))
- return
+ except Exception as ex:
+ log.exception('Unexpected error in send thread: %s' % ex)
+ self.exception(ex)
+ if not self.stop.is_set():
+ self.disconnect(self.auto_reconnect)
def exception(self, exception):
"""