summaryrefslogtreecommitdiff
path: root/slixmpp
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-07-21 00:57:22 +0200
committermathieui <mathieui@mathieui.net>2015-07-21 00:58:52 +0200
commit2ce931cb7a5a110f2fc7c97a0911b99f68bd966a (patch)
treee62dc2464657926c74d9380302f681979a57ecae /slixmpp
parent84eddd2ed282e13d1550527e6c66eae7ea4dc9bf (diff)
downloadslixmpp-2ce931cb7a5a110f2fc7c97a0911b99f68bd966a.tar.gz
slixmpp-2ce931cb7a5a110f2fc7c97a0911b99f68bd966a.tar.bz2
slixmpp-2ce931cb7a5a110f2fc7c97a0911b99f68bd966a.tar.xz
slixmpp-2ce931cb7a5a110f2fc7c97a0911b99f68bd966a.zip
Add a waiting time before reconnecting automatically
Punishing a server for being down by sending more traffic is not a nice thing to do. Taking 100% of the CPU is not nice either.
Diffstat (limited to 'slixmpp')
-rw-r--r--slixmpp/xmlstream/xmlstream.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py
index 866368bd..35d57869 100644
--- a/slixmpp/xmlstream/xmlstream.py
+++ b/slixmpp/xmlstream/xmlstream.py
@@ -72,6 +72,8 @@ class XMLStream(asyncio.BaseProtocol):
# The socket the is used internally by the transport object
self.socket = None
+ self.connect_loop_wait = 0
+
self.parser = None
self.xml_depth = 0
self.xml_root = None
@@ -301,6 +303,7 @@ class XMLStream(asyncio.BaseProtocol):
# and try (host, port) as a last resort
self.dns_answers = None
+ yield from asyncio.sleep(self.connect_loop_wait)
try:
yield from self.loop.create_connection(lambda: self,
self.address[0],
@@ -312,7 +315,10 @@ class XMLStream(asyncio.BaseProtocol):
except OSError as e:
log.debug('Connection failed: %s', e)
self.event("connection_failed", e)
+ self.connect_loop_wait = self.connect_loop_wait * 2 + 1
asyncio.async(self._connect_routine())
+ else:
+ self.connect_loop_wait = 0
def process(self, *, forever=True, timeout=None):
"""Process all the available XMPP events (receiving or sending data on the