summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorBrian Beggs <macdiesel@gmail.com>2010-06-10 10:52:58 -0400
committerBrian Beggs <macdiesel@gmail.com>2010-06-10 10:52:58 -0400
commitf659e3081e09c88c25bebee3b08c767575b68dd4 (patch)
tree06c2dbc0a51123e596f15aaac257cc8379a39e06 /sleekxmpp/xmlstream/xmlstream.py
parent1aa34cb0fc19c8845628d0a55b03c20dc993fcbd (diff)
parentbf2bf29fc69fa82d8b0a882c99395ae25b11ab69 (diff)
downloadslixmpp-f659e3081e09c88c25bebee3b08c767575b68dd4.tar.gz
slixmpp-f659e3081e09c88c25bebee3b08c767575b68dd4.tar.bz2
slixmpp-f659e3081e09c88c25bebee3b08c767575b68dd4.tar.xz
slixmpp-f659e3081e09c88c25bebee3b08c767575b68dd4.zip
Merge remote branch 'tom/hacks'
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index cc5e1ec8..6dbe7b30 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -101,19 +101,16 @@ class XMLStream(object):
def connect(self, host='', port=0, use_ssl=None, use_tls=None):
"Establish a socket connection to the given XMPP server."
- if not self.state.transition('disconnected','connecting'):
- logging.warning("Can't connect now; Already in state %s", self.state.current_state())
+
+ if not self.state.transition('disconnected','connected',
+ func=self.connectTCP, args=[host, port, use_ssl, use_tls] ):
+
+ if self.state['connected']: logging.debug('Already connected')
+ else: logging.warning("Connection failed" )
return False
- try:
- return self.connectTCP(host, port, use_ssl, use_tls)
- finally:
- # attempt to ensure once a connection attempt starts, we leave either in the
- # 'connected' or 'disconnected' state. Otherwise the connect method is not reentrant
- if self.state['connecting']:
- if not self.state.transition('connecting','disconnected'):
- logging.error("Couldn't return to the 'disconnected' state after connection failure!")
-
+ logging.debug('Connection complete.')
+ return True
# TODO currently a caller can't distinguish between "connection failed" and
# "we're already trying to connect from another thread"
@@ -148,9 +145,6 @@ class XMLStream(object):
self.socket.connect(self.address)
self.filesocket = self.socket.makefile('rb', 0)
- if not self.state.transition('connecting','connected'):
- logging.error( "State transition error!!!! Shouldn't have happened" )
- logging.debug('connect complete.')
return True
except socket.error as serr: