summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorThom Nichols <tmnichols@gmail.com>2010-06-29 16:48:15 -0400
committerThom Nichols <tmnichols@gmail.com>2010-06-29 16:48:15 -0400
commit5d87a54913a502b027d4df657a0da1a07a465d7d (patch)
tree64bf60ccead6ea9cf436f19c9cb4dfd237ba9ec8 /sleekxmpp/xmlstream
parentbbf1cb8ba2e913e2c72723a3d0739d499655a5be (diff)
parent8bdfa770245ec02efbecf81bc598faa2b66a64f4 (diff)
downloadslixmpp-5d87a54913a502b027d4df657a0da1a07a465d7d.tar.gz
slixmpp-5d87a54913a502b027d4df657a0da1a07a465d7d.tar.bz2
slixmpp-5d87a54913a502b027d4df657a0da1a07a465d7d.tar.xz
slixmpp-5d87a54913a502b027d4df657a0da1a07a465d7d.zip
Merge branch 'hacks' of github.com:tomstrummer/SleekXMPP into hacks
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 6dbe7b30..b669a31d 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -59,7 +59,7 @@ class XMLStream(object):
self.ssl_support = ssl_support
self.escape_quotes = escape_quotes
self.state = statemachine.StateMachine(('disconnected','connecting',
- 'connected'))
+ 'connected'))
self.should_reconnect = True
self.setSocket(socket)
@@ -240,7 +240,7 @@ class XMLStream(object):
if self.should_reconnect:
self.disconnect(reconnect=True)
- logging.debug('Quitting Process thread')
+ logging.debug('Quitting Process thread')
def __readXML(self):
"Parses the incoming stream, adding to xmlin queue as it goes"
@@ -302,23 +302,24 @@ class XMLStream(object):
return True
def disconnect(self, reconnect=False):
- if not self.state.transition('connected','disconnected'):
- logging.warning("Already disconnected.")
- return
- logging.debug("Disconnecting...")
- self.sendRaw(self.stream_footer)
- time.sleep(5)
- #send end of stream
- #wait for end of stream back
- try:
-# self.socket.shutdown(socket.SHUT_RDWR)
- self.socket.close()
- except socket.error as (errno,strerror):
- logging.exception("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror))
- try:
- self.filesocket.close()
- except socket.error as (errno,strerror):
- logging.exception("Error closing filesocket.")
+ with self.state.transition_ctx('connected','disconnected') as locked:
+ if not locked:
+ logging.warning("Already disconnected.")
+ return
+ logging.debug("Disconnecting...")
+ self.sendRaw(self.stream_footer)
+ time.sleep(5)
+ #send end of stream
+ #wait for end of stream back
+ try:
+# self.socket.shutdown(socket.SHUT_RDWR)
+ self.socket.close()
+ except socket.error as (errno,strerror):
+ logging.exception("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror))
+ try:
+ self.filesocket.close()
+ except socket.error as (errno,strerror):
+ logging.exception("Error closing filesocket.")
if reconnect: self.connect()