]> git.eshelyaron.com Git - emacs.git/commitdiff
Use smarter default for erc-server-reconnect-function
authorF. Jason Park <jp@neverwas.me>
Fri, 29 Nov 2024 23:56:47 +0000 (15:56 -0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:18:58 +0000 (16:18 +0100)
* doc/misc/erc.texi (Sample Configuration): Remove customization in
`use-package' declaration for `erc-server-reconnect-function' as well as
related language in the customization walk-through.  Do this because the
new default incorporates `erc-server-delayed-check-reconnect' behavior
for compatible connect functions.
* etc/ERC-NEWS: Announce new default for `erc-server-reconnect-function'.
* lisp/erc/erc-backend.el (erc-server-reconnect-function): Change
default to `erc-server-prefer-check-reconnect'.
(erc-server-delayed-check-reconnect): Use `process-send-string' instead
of `send-string'.
(erc--server-delayed-check-connectors): New variable.
(erc-server-prefer-check-reconnect): New function.
* test/lisp/erc/erc-scenarios-base-auto-recon.el
(erc-scenarios-base-auto-recon-unavailable)
(erc-scenarios-base-auto-recon-no-proto): Remove unnecessary
`erc-server-reconnect-function' binding because the new default
incorporates the behavior being tested for.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--reconnect-common):
* test/lisp/erc/erc-scenarios-base-compat-rename-bouncer.el
(erc-scenarios-common--base-compat-no-rename-bouncer):
* test/lisp/erc/erc-scenarios-base-netid-bouncer-recon-base.el
(erc-scenarios-base-netid-bouncer--recon-base):
* test/lisp/erc/erc-scenarios-base-netid-bouncer-recon-both.el
(erc-scenarios-base-netid-bouncer--recon-both):
* test/lisp/erc/erc-scenarios-base-netid-bouncer-recon-id.el
(erc-scenarios-base-netid-bouncer--reconnect-id-foo)
(erc-scenarios-base-netid-bouncer--reconnect-id-bar):
* test/lisp/erc/erc-scenarios-base-reconnect.el
(erc-scenarios-base-reconnect-timer)
(erc-scenarios-base-cancel-reconnect):
* test/lisp/erc/erc-scenarios-services-misc.el
(erc-scenarios-services-misc--reconnect-retry-nick):
* test/lisp/erc/erc-scenarios-stamp.el
(erc-scenarios-stamp--date-mode/reconnect): Explicitly bind
`erc-server-reconnect-function' to `erc-server-delayed-reconnect', the
former default, which does not do any probing.  (Bug#62044)

(cherry picked from commit 1c960bda91237c92f9f602bcb8538ad500c0bc49)

12 files changed:
doc/misc/erc.texi
etc/ERC-NEWS
lisp/erc/erc-backend.el
test/lisp/erc/erc-scenarios-base-auto-recon.el
test/lisp/erc/erc-scenarios-base-buffer-display.el
test/lisp/erc/erc-scenarios-base-compat-rename-bouncer.el
test/lisp/erc/erc-scenarios-base-netid-bouncer-recon-base.el
test/lisp/erc/erc-scenarios-base-netid-bouncer-recon-both.el
test/lisp/erc/erc-scenarios-base-netid-bouncer-recon-id.el
test/lisp/erc/erc-scenarios-base-reconnect.el
test/lisp/erc/erc-scenarios-services-misc.el
test/lisp/erc/erc-scenarios-stamp.el

index a3802c8c6bf640b4f440671d99e4e3ef9ff92755..aa62c1b3274cf3e3ff72f10eb472863fe2afbcaa 100644 (file)
@@ -1340,8 +1340,7 @@ settings (@pxref{Sample configuration via Customize}).
   ;; Scroll all windows to prompt when submitting input.
   (erc-scrolltobottom-all t)
 
-  ;; Reconnect automatically using a fancy strategy.
-  (erc-server-reconnect-function #'erc-server-delayed-check-reconnect)
+  ;; Wait a bit longer between automatic reconnect attempts.
   (erc-server-reconnect-timeout 30)
 
   ;; Show new buffers in the current window instead of a split.
@@ -1444,30 +1443,18 @@ descriptions just in case you want to disable them later.  When
 finished, hit @kbd{C-x C-s} or click @samp{[Apply and Save]} atop the
 buffer.
 
-Now do the same for another couple options, this time having to do
-with automatic reconnection.  But instead of searching for their print
-names, try running @kbd{M-x customize-option @key{RET} @samp{<option>}
-@key{RET}}, replacing @samp{<option>} with:
+Now do the same for another option, this time having to do with
+automatic reconnection.  But instead of searching for its print name,
+try running @kbd{M-x customize-option @key{RET}
+erc-server-reconnect-timeout @key{RET}}.  (If it helps, hit @key{TAB}
+for completion.)  As you may have noticed, when customizing options
+individually, each buffer displays but a single option's widget.  For
+@code{erc-server-reconnect-timeout}, you'll encounter a text field
+(instead of a button), which works like those in a typical web form.
+Enter @samp{30} and either hit @kbd{C-x C-s} to save or @key{TAB} over
+to @samp{[State]} and hit @key{RET} followed by @kbd{1} to persist your
+changes.
 
-@itemize @bullet
-@item @code{erc-server-reconnect-function}, a function
-@item @code{erc-server-reconnect-timeout}, a number
-@end itemize
-
-@noindent
-(If it helps, hit @key{TAB} for completion.)  As you may have noticed,
-when customizing options individually, each buffer displays but a
-single option's widget.  When you get to the buffer for ``Erc Server
-Reconnect Function'', you'll see that @samp{[Toggle]} has been
-replaced with @samp{[Value Menu]} and that clicking it reveals three
-choices in a pop-up window.  Enter @kbd{1} to select
-@code{erc-server-delayed-check-reconnect} before @key{TAB}'ing over to
-@samp{[State]} and hitting @key{RET}.  Enter @kbd{1} again, this time
-to persists your changes.
-
-For the final option, @code{erc-server-reconnect-timeout}, you'll
-encounter a text field (instead of a button), which works like those
-in a typical web form.  Enter @samp{30} and hit @kbd{C-x C-s} to save.
 Just for fun, click the group link for @samp{Erc Server} at the bottom
 of the buffer.  You could just as well have set the last two options
 from this ``custom group'' buffer alone, which very much resembles the
index f3c8645f02d42949ee04f27162487c59fdff40c9..b7b49956d060e16973e4ddbdc362a6ada0f0d1c7 100644 (file)
@@ -62,6 +62,12 @@ of concerns and the newer module's "experimental" status, the migration
 was deemed worth any potential disruption, despite this being a point
 release.  ERC appreciates your understanding in this matter.
 
+** Option 'erc-server-reconnect-function' has a new default.
+ERC 5.6 added 'erc-server-delayed-check-reconnect', whose "probing"
+strategy worked better for most users.  While compatibility concerns
+prevented it from becoming the new 'erc-server-reconnect-function'
+outright, a new solution has emerged that defers to it when sensible.
+
 ** Entry-point command 'erc-tls' once again considers option 'erc-port'.
 In its zeal to enforce a preference for TLS connections, ERC 5.5 went a
 bit far in disregarding the useful user option 'erc-port'.  When called
index 9dd368585ebb255234a804c5043e15c3ffb0e947..5c55132a5e5013c93191f993ecc72cfea6126682 100644 (file)
@@ -429,15 +429,16 @@ this value to 120 or greater and/or exploring the option
 means of handling this situation on some servers."
   :type 'number)
 
-(defcustom erc-server-reconnect-function 'erc-server-delayed-reconnect
+(defcustom erc-server-reconnect-function 'erc-server-prefer-check-reconnect
   "Function called by the reconnect timer to create a new connection.
 Called with a server buffer as its only argument.  Potential uses
 include exponential backoff and probing for connectivity prior to
 dialing.  Use `erc-schedule-reconnect' to instead try again later
 and optionally alter the attempts tally."
-  :package-version '(ERC . "5.5")
+  :package-version '(ERC . "5.6.1")
   :type '(choice (function-item erc-server-delayed-reconnect)
                  (function-item erc-server-delayed-check-reconnect)
+                 (function-item erc-server-prefer-check-reconnect)
                  function))
 
 (defcustom erc-split-line-length 440
@@ -879,7 +880,7 @@ Expect BUFFER to be the server buffer for the current connection."
              (sentinel (lambda (proc event)
                          (pcase event
                            ("open\n"
-                            (run-at-time nil nil #'send-string proc
+                            (run-at-time nil nil #'process-send-string proc
                                          (format "PING %d\r\n"
                                                  (time-convert nil 'integer))))
                            ((or "connection broken by remote peer\n"
@@ -901,6 +902,19 @@ Expect BUFFER to be the server buffer for the current connection."
               (set-process-sentinel proc sentinel))
           (file-error (funcall reschedule nil)))))))
 
+(defvar erc--server-delayed-check-connectors
+  '(erc-open-tls-stream erc-open-network-stream)
+  "Functions compatible with `erc-server-delayed-check-reconnect'.")
+
+(defun erc-server-prefer-check-reconnect (buffer)
+  "Defer to another reconnector based on BUFFER's `erc-session-connector'.
+Prefer `erc-server-delayed-check-reconnect' if the connector is known to
+be \"check-aware\".  Otherwise, use `erc-server-delayed-reconnect'."
+  (if (memq (buffer-local-value 'erc-session-connector buffer)
+            erc--server-delayed-check-connectors)
+      (erc-server-delayed-check-reconnect buffer)
+    (erc-server-delayed-reconnect buffer)))
+
 (defun erc-server-filter-function (process string)
   "The process filter for the ERC server."
   (with-current-buffer (process-buffer process)
index 808b1d8c4d475e93fef1e6a18b0d710ced12ac90..d6a114147b3a6d07264be6a5918bf01b48ae7c50 100644 (file)
   (let ((load-path (cons (ert-resource-directory) load-path)))
     (require 'erc-scenarios-common)))
 
+;; This tests `erc-server-delayed-check-reconnect', which is called by
+;; `erc-server-prefer-check-reconnect' (the default value of
+;; `erc-server-reconnect-function' as of ERC 5.6.1).
+
 (defun erc-scenarios-base-auto-recon--get-unused-port ()
   (let ((server (make-network-process :name "*erc-scenarios-base-auto-recon*"
                                       :host "localhost"
@@ -42,7 +46,6 @@
        (port (erc-scenarios-base-auto-recon--get-unused-port))
        (erc--server-reconnect-timeout-scale-function (lambda (_) 1))
        (erc-server-auto-reconnect t)
-       (erc-server-reconnect-function #'erc-server-delayed-check-reconnect)
        (expect (erc-d-t-make-expecter))
        (erc-scenarios-common-dialog "base/reconnect")
        (dumb-server nil))
@@ -89,7 +92,7 @@
         (erc-cmd-RECONNECT "cancel")
         (funcall expect 10 "canceled")))))
 
-;; In this test, a listener accepts but doesn't respond to any messages.
+;; Here, a listener accepts but doesn't respond to any messages.
 
 (ert-deftest erc-scenarios-base-auto-recon-no-proto ()
   :tags '(:expensive-test)
        (erc--server-reconnect-timeout-scale-function (lambda (_) 1))
        (erc--server-reconnect-timeout-check 0.5)
        (erc-server-auto-reconnect t)
-       (erc-server-reconnect-function #'erc-server-delayed-check-reconnect)
        (expect (erc-d-t-make-expecter)))
 
     (ert-info ("Session succeeds but cut short")
index 5c3c526f86d481d16828e58c1af470b6c6961f64..137db955db50a2217958f4e1cbb3581491c46acb 100644 (file)
@@ -40,6 +40,7 @@
        (port (process-contact dumb-server :service))
        (expect (erc-d-t-make-expecter))
        (erc-server-flood-penalty 0.1)
+       (erc-server-reconnect-function #'erc-server-delayed-reconnect)
        (erc-server-auto-reconnect t)
        erc-autojoin-channels-alist)
 
index d1124269e0af4a331ee3ff6cfa8bfe814d60f700..0bba0446ce6925b5fb7a4b82a1ad8cdf45e15d92 100644 (file)
@@ -43,6 +43,7 @@
        (chan-buf-foo (format "#chan@127.0.0.1:%d" port))
        (chan-buf-bar (format "#chan@127.0.0.1:%d<2>" port))
        (expect (erc-d-t-make-expecter))
+       (erc-server-reconnect-function #'erc-server-delayed-reconnect)
        (erc-server-auto-reconnect auto)
        erc-server-buffer-foo erc-server-process-foo
        erc-server-buffer-bar erc-server-process-bar)
index e5453c40e56dbc7d3077dd7da7f680caed35c8db..04ccb86643b03174bdd287cd03d7c654f8970d58 100644 (file)
@@ -26,6 +26,7 @@
 
 (ert-deftest erc-scenarios-base-netid-bouncer--recon-base ()
   :tags '(:expensive-test)
-  (erc-scenarios-common--base-network-id-bouncer--reconnect nil nil))
+  (let ((erc-server-reconnect-function #'erc-server-delayed-reconnect))
+    (erc-scenarios-common--base-network-id-bouncer--reconnect nil nil)))
 
 ;;; erc-scenarios-base-netid-bouncer-recon-base.el ends here
index 09ddcef5fa3cf316f5e7c8aae3ac84d0026fd758..f0939d6204a133908ba30ba094b6198ab9e08463 100644 (file)
@@ -27,6 +27,8 @@
 
 (ert-deftest erc-scenarios-base-netid-bouncer--recon-both ()
   :tags '(:expensive-test)
-  (erc-scenarios-common--base-network-id-bouncer--reconnect 'foo-id 'bar-id))
+  (let ((erc-server-reconnect-function #'erc-server-delayed-reconnect))
+    (erc-scenarios-common--base-network-id-bouncer--reconnect 'foo-id
+                                                              'bar-id)))
 
 ;;; erc-scenarios-base-netid-bouncer-recon-both.el ends here
index 253ab4f72c9435ef727ffe82aae86c1f16694054..d77a428797610da9c0b79501ff0c639e2305f44e 100644 (file)
 
 (ert-deftest erc-scenarios-base-netid-bouncer--reconnect-id-foo ()
   :tags '(:expensive-test)
-  (erc-scenarios-common--base-network-id-bouncer--reconnect 'foo-id nil))
+  (let ((erc-server-reconnect-function #'erc-server-delayed-reconnect))
+    (erc-scenarios-common--base-network-id-bouncer--reconnect 'foo-id nil)))
 
 (ert-deftest erc-scenarios-base-netid-bouncer--reconnect-id-bar ()
   :tags '(:expensive-test)
-  (erc-scenarios-common--base-network-id-bouncer--reconnect nil 'bar-id))
+  (let ((erc-server-reconnect-function #'erc-server-delayed-reconnect))
+    (erc-scenarios-common--base-network-id-bouncer--reconnect nil 'bar-id)))
 
 
 ;;; erc-scenarios-base-netid-bouncer-recon-id.el ends here
index 6f968b9fcbcfff04665c559a68e788ebcb0ba33e..2dc34362fbfc8936c19a7d2b1bfb457525a7835a 100644 (file)
@@ -37,6 +37,7 @@
        (dumb-server (erc-d-run "localhost" t 'timer 'timer 'timer-last))
        (port (process-contact dumb-server :service))
        (expect (erc-d-t-make-expecter))
+       (erc-server-reconnect-function #'erc-server-delayed-reconnect)
        (erc-server-auto-reconnect t)
        erc-autojoin-channels-alist
        erc-server-buffer)
        (dumb-server (erc-d-run "localhost" t 'timer 'timer 'timer-last))
        (port (process-contact dumb-server :service))
        (expect (erc-d-t-make-expecter))
+       (erc-server-reconnect-function #'erc-server-delayed-reconnect)
        (erc-server-auto-reconnect t)
        erc-autojoin-channels-alist
        erc-server-buffer)
index 47d0bcff41a7bd826e68f0ed66a583d7b5f9bde3..ee35e8b93dbf4a7f400da4f470e907c14524c6ed 100644 (file)
        (dumb-server (erc-d-run "localhost" t 'reconnect-retry
                                'reconnect-retry-again))
        (port (process-contact dumb-server :service))
+       (erc-server-reconnect-function #'erc-server-delayed-reconnect)
        (erc-server-auto-reconnect t)
        (erc-modules `(services-regain sasl ,@erc-modules))
        (erc-services-regain-alist
index 2e836e163bc9f1604e1022bc8bf3e9568f7f68d8..b0ec96794fde32f4af6e616c2433c4812e2d551f 100644 (file)
       ((erc-scenarios-common-dialog "base/reconnect")
        (erc-server-flood-penalty 0.1)
        (erc-stamp--tz t)
+       (erc-server-reconnect-function #'erc-server-delayed-reconnect)
        (erc-server-auto-reconnect t)
        ;; Start close to midnight: 2024-06-02T23:58:11.055Z
        (erc-stamp--current-time (if (< emacs-major-version 29)