summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorThom Nichols <tmnichols@gmail.com>2010-06-04 17:00:51 -0400
committerThom Nichols <tmnichols@gmail.com>2010-06-04 17:00:51 -0400
commite7c37c4ec5a31402ba4d3fd95f2ee31d72183a83 (patch)
treecb3f0fd09979e4c9019fed829a4b2b7834be6daa /sleekxmpp
parent919c8c5633acd0d638f39c4a7ec8794fc5e94fff (diff)
downloadslixmpp-e7c37c4ec5a31402ba4d3fd95f2ee31d72183a83.tar.gz
slixmpp-e7c37c4ec5a31402ba4d3fd95f2ee31d72183a83.tar.bz2
slixmpp-e7c37c4ec5a31402ba4d3fd95f2ee31d72183a83.tar.xz
slixmpp-e7c37c4ec5a31402ba4d3fd95f2ee31d72183a83.zip
connect uses the new function-on-state-transition so when the connect method returns you are guaranteed to be either in the 'connected' or 'disconnected' state. Could remove the 'connecting' state except uses it.
Diffstat (limited to 'sleekxmpp')
-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: