summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorBrian Beggs <macdiesel@gmail.com>2010-06-04 12:52:52 -0400
committerBrian Beggs <macdiesel@gmail.com>2010-06-04 12:52:52 -0400
commit1aa34cb0fc19c8845628d0a55b03c20dc993fcbd (patch)
tree9aaf6c5291eb602c3c8b9f4f20e5912cd006f2f5 /sleekxmpp/xmlstream/xmlstream.py
parent3f96226e29ee94eb718d01fa9cd052cfeb4fcfb5 (diff)
parent919c8c5633acd0d638f39c4a7ec8794fc5e94fff (diff)
downloadslixmpp-1aa34cb0fc19c8845628d0a55b03c20dc993fcbd.tar.gz
slixmpp-1aa34cb0fc19c8845628d0a55b03c20dc993fcbd.tar.bz2
slixmpp-1aa34cb0fc19c8845628d0a55b03c20dc993fcbd.tar.xz
slixmpp-1aa34cb0fc19c8845628d0a55b03c20dc993fcbd.zip
Merge remote branch 'tom/hacks'
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 76aecee4..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"
@@ -281,11 +283,12 @@ class XMLStream(object):
data = None
try:
- data = self.sendqueue.get(True,10)
+ data = self.sendqueue.get(True,5)
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,6 +375,7 @@ class XMLStream(object):
try:
event = self.eventqueue.get(True, timeout=5)
except queue.Empty:
+# logging.debug('Nothing on event queue')
event = None
if event is not None:
etype = event[0]