[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Erc-commit] [commit][master] Use better algorithm for enforcing a timeo
From: |
mwolson |
Subject: |
[Erc-commit] [commit][master] Use better algorithm for enforcing a timeout between reconnect attempts |
Date: |
Sun, 14 Oct 2007 00:49:21 -0400 |
commit 4bb22757c7656407b0c076d481a88c59cf2cd443
Author: Michael W. Olson <address@hidden>
Date: Tue Aug 14 00:54:32 2007 -0400
Use better algorithm for enforcing a timeout between reconnect attempts
* erc-backend.el (erc-process-sentinel-2): If we are instructed to try
connecting indefinitely, tell the user that they can stop this by
killing the server buffer. Call the process sentinel by means of
run-at-time, so that there is time to kill the buffer if need be; this
also removes the need for a while loop. Refuse to reconnect again if
erc-server-reconnect-timeout is not an integer.
diff --git a/ChangeLog b/ChangeLog
index 1ad7eb7..b957b34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,13 +6,19 @@
/reconnect is run from a channel buffer whose server buffer has
been deleted. Thanks to jbms for the report.
(erc-process-sentinel-1): Take server buffer as an argument, so
- that we can make sure that it is current. If it is deleted during
- a reconnect attempt, stop trying to reconnect. Fix bug where
- reconnect was not happening when erc-server-reconnect-attempts was
- t. Call erc-server-reconnect-p only once per loop iteration.
+ that we can make sure that it is current.
(erc-process-sentinel): Pass buffer to erc-process-sentinel-1.
(erc-process-sentinel-2): New function split from
- erc-process-sentinel-1.
+ erc-process-sentinel-1. If server buffer is deleted during a
+ reconnect attempt, stop trying to reconnect. Fix bug where
+ reconnect was not happening when erc-server-reconnect-attempts was
+ t. Call erc-server-reconnect-p only once each time. If we are
+ instructed to try connecting indefinitely, tell the user that they
+ can stop this by killing the server buffer. Call the process
+ sentinel by means of run-at-time, so that there is time to kill
+ the buffer if need be; this also removes the need for a while
+ loop. Refuse to reconnect again if erc-server-reconnect-timeout
+ is not an integer.
* erc.el (erc-command-no-process-p): Fix bug: the return value of
erc-extract-command-from-line is a list rather than a single
diff --git a/erc-backend.el b/erc-backend.el
index 1f2fc0c..f4c87e2 100644
--- a/erc-backend.el
+++ b/erc-backend.el
@@ -612,33 +612,36 @@ EVENT is the message received from the closed connection
process."
(defun erc-process-sentinel-2 (event buffer)
"Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
- (with-current-buffer buffer
- (let ((again t)
- reconnect-p)
- (while again
- (setq again nil)
- (setq reconnect-p (erc-server-reconnect-p event))
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (let ((reconnect-p (erc-server-reconnect-p event)))
(erc-display-message nil 'error (current-buffer)
(if reconnect-p 'disconnected
'disconnected-noreconnect))
- (if reconnect-p
- (condition-case err
- (progn
- (setq erc-server-reconnecting nil)
- (erc-server-reconnect)
- (setq erc-server-reconnect-count 0))
- (error (when (buffer-live-p buffer)
- (set-buffer buffer)
- (when (integerp erc-server-reconnect-attempts)
+ (if (not reconnect-p)
+ ;; terminate, do not reconnect
+ (erc-display-message nil 'error (current-buffer)
+ 'terminated ?e event)
+ ;; reconnect
+ (condition-case err
+ (progn
+ (setq erc-server-reconnecting nil)
+ (erc-server-reconnect)
+ (setq erc-server-reconnect-count 0))
+ (error (when (buffer-live-p buffer)
+ (set-buffer buffer)
+ (if (integerp erc-server-reconnect-attempts)
(setq erc-server-reconnect-count
- (1+ erc-server-reconnect-count)))
- ;; TODO: Make this use a one-time timer
- ;; instead of sit-for
- (sit-for erc-server-reconnect-timeout)
- (setq again t))))
- ;; terminate, do not reconnect
- (erc-display-message nil 'error (current-buffer)
- 'terminated ?e event))))))
+ (1+ erc-server-reconnect-count))
+ (message "%s ... %s"
+ "Reconnecting until we succeed"
+ "kill the server buffer to stop"))
+ (if (integerp erc-server-reconnect-timeout)
+ (run-at-time erc-server-reconnect-timeout nil
+ #'erc-process-sentinel-2
+ event buffer)
+ (error (concat "`erc-server-reconnect-timeout`"
+ " must be an integer")))))))))))
(defun erc-process-sentinel-1 (event buffer)
"Called when `erc-process-sentinel' has decided that we're disconnecting.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Erc-commit] [commit][master] Use better algorithm for enforcing a timeout between reconnect attempts,
mwolson <=