summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorThom Nichols <tmnichols@gmail.com>2010-06-03 07:47:27 -0400
committerThom Nichols <tmnichols@gmail.com>2010-06-03 07:47:27 -0400
commit1c32668e18c0cbf840694c66a6f724b2d3cb8f29 (patch)
tree30a508197858c47f5885a99be8dc270788c9524c /sleekxmpp
parent1f3cfb98f155511bc10d9630534e39adaa50feae (diff)
downloadslixmpp-1c32668e18c0cbf840694c66a6f724b2d3cb8f29.tar.gz
slixmpp-1c32668e18c0cbf840694c66a6f724b2d3cb8f29.tar.bz2
slixmpp-1c32668e18c0cbf840694c66a6f724b2d3cb8f29.tar.xz
slixmpp-1c32668e18c0cbf840694c66a6f724b2d3cb8f29.zip
fixed quiesce algorithm; state transition if connect fails; note about use_tls instance variable.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index e0b3a23c..af95c2bf 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -101,8 +101,16 @@ class XMLStream(object):
def connect(self, host='', port=0, use_ssl=None, use_tls=None):
"Link to connectTCP"
- if self.state.transition('disconnected', 'connecting'):
- return self.connectTCP(host, port, use_ssl, use_tls)
+ 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
+
+ # TODO currently a caller can't distinguish between "connection failed" and
+ # "we're already trying to connect from another thread"
def connectTCP(self, host='', port=0, use_ssl=None, use_tls=None, reattempt=True):
"Connect and create socket"
@@ -119,6 +127,7 @@ class XMLStream(object):
if use_ssl is not None:
self.use_ssl = use_ssl
if use_tls is not None:
+ # TODO this variable doesn't seem to be used for anything!
self.use_tls = use_tls
if sys.version_info < (3, 0):
self.socket = filesocket.Socket26(socket.AF_INET, socket.SOCK_STREAM)
@@ -146,9 +155,9 @@ class XMLStream(object):
if not reattempt: return False
# quiesce if rconnection fails:
- # This code based loosely on Twisted internet.protocol
+ # This algorithm based loosely on Twisted internet.protocol
# http://twistedmatrix.com/trac/browser/trunk/twisted/internet/protocol.py#L310
- delay = min(delay * RECONNECT_QUIESCE_JITTER, RECONNECT_MAX_DELAY)
+ delay = min(delay * RECONNECT_QUIESCE_FACTOR, RECONNECT_MAX_DELAY)
delay = random.normalvariate(delay, delay * RECONNECT_QUIESCE_JITTER)
logging.debug('Waiting %fs until next reconnect attempt...', delay)
time.sleep(delay)