]> git.eshelyaron.com Git - emacs.git/commitdiff
Handle connection errors in rcirc-keepalive
authorPhilip Kaludercic <philipk@posteo.net>
Sun, 17 Apr 2022 12:21:14 +0000 (14:21 +0200)
committerPhilip Kaludercic <philipk@posteo.net>
Sun, 17 Apr 2022 12:22:25 +0000 (14:22 +0200)
* rcirc.el (rcirc-reconnect-delay): Declare variable before it is
defined.
(rcirc-keepalive): Handle rcirc-closed-connection, respecting
rcirc-reconnect-delay.
(rcirc-closed-connection): Add new error type.
(rcirc-send-string): Throw rcirc-closed-connection instead of a
generic error.

lisp/net/rcirc.el

index 5fe65cc7b3e945b42c9c2f19543155c636b5b2e4..f34be6daf3f277b8df1d963f3280cc72107268b5 100644 (file)
@@ -771,18 +771,26 @@ SERVER-PLIST is the property list for the server."
           (yes-or-no-p "Encrypt connection?"))
       'tls 'plain))
 
+(defvar rcirc-reconnect-delay)
 (defun rcirc-keepalive ()
   "Send keep alive pings to active rcirc processes.
 Kill processes that have not received a server message since the
 last ping."
   (if (rcirc-process-list)
       (mapc (lambda (process)
-             (with-rcirc-process-buffer process
-               (when (not rcirc-connecting)
-                  (rcirc-send-ctcp process
-                                   rcirc-nick
-                                   (format "KEEPALIVE %f"
-                                           (float-time))))))
+              (with-rcirc-process-buffer process
+                (when (not rcirc-connecting)
+                  (condition-case nil
+                      (rcirc-send-ctcp process
+                                       rcirc-nick
+                                       (format "KEEPALIVE %f"
+                                               (float-time)))
+                    (rcirc-closed-connection
+                     (if (zerop rcirc-reconnect-delay)
+                         (message "rcirc: Connection to %s closed"
+                                  (process-name process))
+                       (rcirc-reconnect process))
+                     (message ""))))))
             (rcirc-process-list))
     ;; no processes, clean up timer
     (when (timerp rcirc-keepalive-timer)
@@ -1136,6 +1144,8 @@ used as the message body."
   "Check if PROCESS is open or running."
   (memq (process-status process) '(run open)))
 
+(define-error 'rcirc-closed-connection "Network connection not open")
+
 (defun rcirc-send-string (process &rest parts)
   "Send PROCESS a PARTS plus a newline.
 PARTS may contain a `:' symbol, to designate that the next string
@@ -1153,8 +1163,7 @@ element in PARTS is a list, append it to PARTS."
                          rcirc-encode-coding-system)
                         "\n")))
     (unless (rcirc--connection-open-p process)
-      (error "Network connection to %s is not open"
-             (process-name process)))
+      (signal 'rcirc-closed-connection process))
     (rcirc-debug process string)
     (process-send-string process string)))