summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorThom Nichols <tmnichols@gmail.com>2010-06-03 15:21:26 -0400
committerThom Nichols <tmnichols@gmail.com>2010-06-03 15:21:26 -0400
commit919c8c5633acd0d638f39c4a7ec8794fc5e94fff (patch)
treefbc20cff41de16f7870af78e6b4abe17f06a78a0 /sleekxmpp/xmlstream
parentf54501a3465b84f1be157c1ba99df854dbeaed1d (diff)
downloadslixmpp-919c8c5633acd0d638f39c4a7ec8794fc5e94fff.tar.gz
slixmpp-919c8c5633acd0d638f39c4a7ec8794fc5e94fff.tar.bz2
slixmpp-919c8c5633acd0d638f39c4a7ec8794fc5e94fff.tar.xz
slixmpp-919c8c5633acd0d638f39c4a7ec8794fc5e94fff.zip
tweaked connectTCP call slightly to reduce possibility of 'connecting' state limbo
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index c407a335..cc5e1ec8 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -100,18 +100,20 @@ class XMLStream(object):
self.filesocket = filesocket
def connect(self, host='', port=0, use_ssl=None, use_tls=None):
- "Link to connectTCP"
+ "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())
return False
- if not self.connectTCP(host, port, use_ssl, use_tls):
- # return to the 'disconnected' state if connect failed:
- # otherwise the connect method is not reentrant
- if not self.state.transition('connecting','disconnected'):
- logging.error("Couldn't transition to the 'disconnected' state!")
- return False
- return True
+ 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!")
+
# TODO currently a caller can't distinguish between "connection failed" and
# "we're already trying to connect from another thread"
@@ -285,7 +287,8 @@ class XMLStream(object):
logging.debug("SEND: %s" % data)
self.socket.sendall(data.encode('utf-8'))
except queue.Empty:
- logging.debug('nothing on send queue')
+# logging.debug('Nothing on send queue')
+ pass
except socket.timeout:
# this is to prevent a thread blocked indefinitely
logging.debug('timeout sending packet data')
@@ -372,7 +375,7 @@ class XMLStream(object):
try:
event = self.eventqueue.get(True, timeout=5)
except queue.Empty:
- logging.debug('Nothing on event queue')
+# logging.debug('Nothing on event queue')
event = None
if event is not None:
etype = event[0]