Subject: Re: bug#4589: 23.1; ERC reconnection -vs- /disconnect

From: Vivek Dasmohapatra <[email-masked]>
Date: Thu, 11 Feb 2010 23:16:27 +0000 (GMT)

Tags: patch

Note: There is no "/disconnect" command, but:
       "/quit",  "/exit" and "/bye" should all work.

You should also note that the reconnect loop isn't actually supposed
to be infinite, the default config _should_ stop after two tries, but
that is addressed in a separate patch in bug #4048

In any case, regardless of the number of attempts configured, issuing
an explicit quit with this patch applied should put a stop to further
[automatic] attempts.

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -579,20 +579,22 @@ Make sure you are in an ERC buffer when running this."
 (defsubst erc-server-reconnect-p (event)
   "Return non-nil if ERC should attempt to reconnect automatically.
 EVENT is the message received from the closed connection process."
-  (or erc-server-reconnecting
-      (and erc-server-auto-reconnect
-           (not erc-server-banned)
-           (not erc-server-error-occurred)
-           ;; make sure we don't infinitely try to reconnect, unless the
-           ;; user wants that
-           (or (eq erc-server-reconnect-attempts t)
-               (and (integerp erc-server-reconnect-attempts)
-                    (< erc-server-reconnect-count
-                       erc-server-reconnect-attempts)))
-           (or erc-server-timed-out
-               (not (string-match "^deleted" event)))
-           ;; open-network-stream-nowait error for connection refused
-           (not (string-match "^failed with code 111" event)))))
+  (and (not erc-server-quitting)   ;; user issued an explicit quit, give up now
+       (or erc-server-reconnecting ;; user issued explicit reconnect
+           ;; otherwise go through the full spectrum of checks:
+           (and erc-server-auto-reconnect
+                (not erc-server-banned)
+                (not erc-server-error-occurred)
+                ;; make sure we don't infinitely try to reconnect, unless the
+                ;; user wants that
+                (or (eq erc-server-reconnect-attempts t)
+                    (and (integerp erc-server-reconnect-attempts)
+                         (< erc-server-reconnect-count
+                            erc-server-reconnect-attempts)))
+                (or erc-server-timed-out
+                    (not (string-match "^deleted" event)))
+                ;; open-network-stream-nowait error for connection refused
+                (not (string-match "^failed with code 111" event))))))
 
 (defun erc-process-sentinel-2 (event buffer)
   "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."