summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2010-02-15 02:13:44 -0800
committerNathan Fritz <fritzy@netflint.net>2010-02-15 02:13:44 -0800
commit58375955a9b832356ba68cc1f9ecb3bc274b6922 (patch)
tree3f0d2a681879cec94301339155ba72a6f767d519 /sleekxmpp/xmlstream/xmlstream.py
parent06fa1fcf332c9e0623dff90db8d1daacdfac87f1 (diff)
downloadslixmpp-58375955a9b832356ba68cc1f9ecb3bc274b6922.tar.gz
slixmpp-58375955a9b832356ba68cc1f9ecb3bc274b6922.tar.bz2
slixmpp-58375955a9b832356ba68cc1f9ecb3bc274b6922.tar.xz
slixmpp-58375955a9b832356ba68cc1f9ecb3bc274b6922.zip
added send queueing to avoid mixed sending
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 0cdfdf96..44f83840 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -66,6 +66,7 @@ class XMLStream(object):
self.stream_footer = "</stream>"
self.eventqueue = queue.Queue()
+ self.sendqueue = queue.Queue()
self.namespace_map = {}
@@ -139,12 +140,17 @@ class XMLStream(object):
for t in range(0, HANDLER_THREADS):
self.__thread['eventhandle%s' % t] = threading.Thread(name='eventhandle%s' % t, target=self._eventRunner)
self.__thread['eventhandle%s' % t].start()
+ self.__thread['sendthread'] = threading.Thread(name='sendthread', target=self._sendThread)
+ self.__thread['sendthread'].start()
if threaded:
self.__thread['process'] = threading.Thread(name='process', target=self._process)
self.__thread['process'].start()
else:
self._process()
+ def schedule(self, seconds, handler, args=None):
+ threading.Timer(seconds, handler, args).start()
+
def _process(self):
"Start processing the socket."
firstrun = True
@@ -222,19 +228,23 @@ class XMLStream(object):
if event == b'start':
edepth += 1
+ def _sendThread(self):
+ while True:
+ data = self.sendqueue.get(True)
+ logging.debug("SEND: %s" % data)
+ try:
+ self.socket.send(data.encode('utf-8'))
+ #self.socket.send(bytes(data, "utf-8"))
+ #except socket.error,(errno, strerror):
+ except:
+ self.state.set('connected', False)
+ if self.state.reconnect:
+ logging.error("Disconnected. Socket Error.")
+ traceback.print_exc()
+ self.disconnect(reconnect=True)
+
def sendRaw(self, data):
- logging.debug("SEND: %s" % data)
- try:
- self.socket.send(data.encode('utf-8'))
- #self.socket.send(bytes(data, "utf-8"))
- #except socket.error,(errno, strerror):
- except:
- self.state.set('connected', False)
- if self.state.reconnect:
- logging.error("Disconnected. Socket Error.")
- traceback.print_exc()
- self.disconnect(reconnect=True)
- return False
+ self.sendqueue.put(data)
return True
def disconnect(self, reconnect=False):