erc-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Erc-commit] [commit][emacs22] Kill hung IRC processes.


From: mwolson
Subject: [Erc-commit] [commit][emacs22] Kill hung IRC processes.
Date: Sun, 14 Oct 2007 00:48:24 -0400

commit 287dc8e8408d52c8bdcffe73d35138ba224db077
Author: Michael Olson <address@hidden>
Date:   Sun Aug 6 07:03:00 2006 +0000

    Kill hung IRC processes.
    
    * erc-backend.el (erc-server-ping-timer-alist): New variable that keeps
      track of ping timers according to their associated server.
      (erc-server-last-received-time): New variable that specifies the time
      of the last message we received from the server.  This is used to
      detect hung processes.
      (erc-server-setup-periodical-server-ping): If the server buffer no
      longer exists, cancel the timer.  If the server process has not given
      us a message, including PING responses, since the last PING, kill it.
      This is necessary to deal with some aberrant freenode behavior.  Idea
      taken from rcirc.
    
    * erc.el (erc-select-startup-file): Fix bug introduced by recent change.
    git-archimport-id: address@hidden/erc--main--0--patch-35

diff --git a/ChangeLog b/ChangeLog
index 8892366..42b6daf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,9 +2,20 @@
 
        * erc-backend.el (erc-server-send-queue): Update from Circe
        version of this function.
+       (erc-server-ping-timer-alist): New variable that keeps track of
+       ping timers according to their associated server.
+       (erc-server-last-received-time): New variable that specifies the
+       time of the last message we received from the server.  This is
+       used to detect hung processes.
+       (erc-server-setup-periodical-server-ping): If the server buffer no
+       longer exists, cancel the timer.  If the server process has not
+       given us a message, including PING responses, since the last PING,
+       kill it.  This is necessary to deal with some aberrant freenode
+       behavior.  Idea taken from rcirc.
 
        * erc.el (erc-arrange-session-in-multiple-windows): Fix bug with
        multi-tty Emacs.
+       (erc-select-startup-file): Fix bug introduced by recent change.
 
 2006-08-05  Michael Olson  <address@hidden>
 
diff --git a/erc-backend.el b/erc-backend.el
index 81ab0b8..b73433c 100644
--- a/erc-backend.el
+++ b/erc-backend.el
@@ -174,6 +174,9 @@ WALLCHOPS - supports sending messages to all operators in a 
channel")
 
 ;;; Server and connection state
 
+(defvar erc-server-ping-timer-alist nil
+  "Mapping of server buffers to their specific ping timer.")
+
 (defvar erc-server-connected nil
   "Non-nil if the `current-buffer' is associated with an open IRC connection.
 This variable is buffer-local.")
@@ -202,6 +205,11 @@ This is useful for flood protection.")
 This is useful for flood protection.")
 (make-variable-buffer-local 'erc-server-last-ping-time)
 
+(defvar erc-server-last-received-time nil
+  "Time the last message was received from the server.
+This is useful for detecting hung connections.")
+(make-variable-buffer-local 'erc-server-last-received-time)
+
 (defvar erc-server-lag nil
   "Calculated server lag time in seconds.
 This variable is only set in a server buffer.")
@@ -407,12 +415,25 @@ Currently this is called by `erc-send-input'."
           (run-with-timer
            4 erc-server-send-ping-interval
            (lambda (buf)
-             (when (buffer-live-p buf)
-               (with-current-buffer buf
-                 (erc-server-send
-                  (format "PING %.0f"
-                          (erc-current-time))))))
-           (current-buffer)))))
+             (if (buffer-live-p buf)
+                 (with-current-buffer buf
+                   (if (> (erc-time-diff (erc-current-time)
+                                         erc-server-last-received-time)
+                          erc-server-send-ping-interval)
+                       ;; if the process is hung, kill it
+                       (kill-process erc-server-process)
+                     (erc-server-send
+                      (format "PING %.0f"
+                              (erc-current-time)))))
+               ;; remove timer if the server buffer has been killed
+               (let ((timer (assq buf erc-server-ping-timer-alist)))
+                 (when timer
+                   (erc-cancel-timer (cdr timer))
+                   (setcar timer nil)))))
+           (current-buffer)))
+    (setq erc-server-ping-timer-alist (cons (cons (current-buffer)
+                                                  erc-server-ping-handler)
+                                            erc-server-ping-timer-alist))))
 
 (defun erc-server-process-alive ()
   "Return non-nil when `erc-server-process' is open or running."
@@ -434,8 +455,10 @@ We will store server variables in the current buffer."
     (message "%s...done" msg))
   ;; Misc server variables
   (setq erc-server-quitting nil)
-  (setq erc-server-last-sent-time (erc-current-time))
-  (setq erc-server-last-ping-time (erc-current-time))
+  (let ((time (erc-current-time)))
+    (setq erc-server-last-sent-time time)
+    (setq erc-server-last-ping-time time)
+    (setq erc-server-last-received-time time))
   (setq erc-server-lines-sent 0)
   ;; last peers (sender and receiver)
   (setq erc-server-last-peers '(nil . nil))
@@ -460,6 +483,7 @@ We will store server variables in the current buffer."
 (defun erc-server-filter-function (process string)
   "The process filter for the ERC server."
   (with-current-buffer (process-buffer process)
+    (setq erc-server-last-received-time (current-time))
     ;; If you think this is written in a weird way - please refer to the
     ;; docstring of `erc-server-processing-p'
     (if erc-server-processing-p
diff --git a/erc.el b/erc.el
index 2c177a5..e237003 100644
--- a/erc.el
+++ b/erc.el
@@ -5250,7 +5250,7 @@ If FILE is found, return the path to it."
 See also `erc-startup-file-list'."
   (catch 'found
     (dolist (f erc-startup-file-list)
-      (setq f (convert-standard-file-name f))
+      (setq f (convert-standard-filename f))
       (when (file-readable-p f)
        (throw 'found f)))))
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]