- Trying to connect to server every 20 seconds forever is extremely rude to its owner. Let's be polite and do exponential back-off. (See #2411)

- [PyOpenSSL] Ported [7443] to pyopenssl branch.
This commit is contained in:
junglecow 2006-12-08 21:19:01 +00:00
parent 4a58bc4797
commit 7c0696093a
2 changed files with 7 additions and 5 deletions

View File

@ -123,6 +123,8 @@ class NBCommonClient(CommonClient):
self.on_connect_failure(retry)
def _on_connected(self):
# connect succeeded, so no need of this callback anymore
self.on_connect_failure = None
self.connected = 'tcp'
if self._Ssl:
transports_nb.NonBlockingTLS().PlugIn(self, now=1)

View File

@ -342,11 +342,11 @@ class NonBlockingTcp(PlugIn, IdleObject):
def pollin(self):
self._do_receive()
def pollend(self):
def pollend(self, retry=False):
conn_failure_cb = self.on_connect_failure
self.disconnect()
if conn_failure_cb:
conn_failure_cb()
conn_failure_cb(retry)
def disconnect(self):
if self.state == -2: # already disconnected
@ -442,8 +442,8 @@ class NonBlockingTcp(PlugIn, IdleObject):
if errnum in (ERR_DISCONN, errno.ECONNRESET, errno.ENOTCONN, errno.ESHUTDOWN):
self.DEBUG(errtxt, 'error')
log.error("Got Disconnected: " + errtxt)
self.pollend()
# don't proccess result, cas it will raise error
self.pollend(retry=(errnum in (ERR_DISCONN, errno.ECONNRESET)))
# don't process result, because it will raise an error
return
if received is None:
@ -451,7 +451,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.DEBUG(errtxt, 'error')
log.error("Error: " + errtxt)
if self.state >= 0:
self.pollend()
self.pollend(retry=True)
return
received = ''