summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorTom Nichols <tmnichols@gmail.com>2010-07-06 14:16:46 -0400
committerTom Nichols <tmnichols@gmail.com>2010-07-06 14:16:46 -0400
commit259dffeb6e4da0b879784ae9642f43c01b95811b (patch)
tree495255dc66de2ff35f2fb0f0fb1f4aa0a55d4e13 /sleekxmpp/xmlstream
parent0a30e6c0175b13cef400d4cba27eaf145b07d365 (diff)
downloadslixmpp-259dffeb6e4da0b879784ae9642f43c01b95811b.tar.gz
slixmpp-259dffeb6e4da0b879784ae9642f43c01b95811b.tar.bz2
slixmpp-259dffeb6e4da0b879784ae9642f43c01b95811b.tar.xz
slixmpp-259dffeb6e4da0b879784ae9642f43c01b95811b.zip
send now has a priority and an 'init' parameter to denote stanzas that may be sent prior to session establishment.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py6
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py13
2 files changed, 8 insertions, 11 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index 34513807..b9267b88 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -383,7 +383,7 @@ class StanzaBase(ElementBase):
def exception(self, e):
logging.error(traceback.format_tb(e))
- def send(self, priority=False):
- if priority: self.stream.sendPriorityRaw(self.__str__())
- else: self.stream.sendRaw(self.__str__())
+ def send(self, priority=5, init=False):
+ self.stream.sendRaw(self.__str__(), priority, init)
+
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index fd0b0fa0..59b0cc62 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -219,7 +219,7 @@ class XMLStream(object):
while not self.quit.is_set():
if not self.state.ensure('connected',wait=2, block_on_transition=True): continue
try:
- self.sendPriorityRaw(self.stream_header)
+ self.sendRaw(self.stream_header, priority=0, init=True)
self.__readXML() # this loops until the stream is terminated.
except socket.timeout:
# TODO currently this will re-send a stream header if this exception occurs.
@@ -299,12 +299,9 @@ class XMLStream(object):
reconnect = (self.should_reconnect and not self.quit.is_set())
self.disconnect(reconnect=reconnect, error=True)
- def sendRaw(self, data):
- self.sendqueue.put((1, data))
- return True
-
- def sendPriorityRaw(self, data):
- self.sendqueue.put((0, data))
+ def sendRaw( self, data, priority=5, init=False ):
+ if not self.state.ensure('connected'): return False
+ self.sendqueue.put((priority, data))
return True
def disconnect(self, reconnect=False, error=False):
@@ -316,7 +313,7 @@ class XMLStream(object):
logging.debug("Disconnecting...")
# don't send a footer on error; if the stream is already closed,
# this won't get sent until the stream is re-initialized!
- if not error: self.sendRaw(self.stream_footer) #send end of stream
+ if not error: self.sendRaw(self.stream_footer,init=True) #send end of stream
try:
# self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close()