bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#19292: 24.3; [PATCH] erc-server-ping-timer-alist now has at most one


From: Dima Kogan
Subject: bug#19292: 24.3; [PATCH] erc-server-ping-timer-alist now has at most one timer per buffer
Date: Sat, 06 Dec 2014 14:49:13 -0800

This alist was meant to map buffers to timers, but the "push" function
was not checking for already-existing timers.  This was causing a
flood of PINGs being queued (because more than one timer was inserting
those), and the flood-control logic would block those from going
through quickly.

This patch checks for existing timers in the alist before adding new
ones.  If a timer already exists, it is cancelled and overwritten.

>From 421c00345c3407fff7044092c458316c6da870a6 Mon Sep 17 00:00:00 2001
From: Dima Kogan <address@hidden>
Date: Sat, 6 Dec 2014 14:46:51 -0800
Subject: [PATCH] erc-server-ping-timer-alist now has at most one timer per
 buffer

This alist was meant to map buffers to timers, but the "push" function
was not checking for already-existing timers.  This was causing a
flood of PINGs being queued (because more than one timer was inserting
those), and the flood-control logic would block those from going
through quickly.

This patch checks for existing timers in the alist before adding new
ones.  If a timer already exists, it is cancelled and overwritten.
---
 lisp/erc/erc-backend.el | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index fb22f58..bedb20f 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -493,9 +493,19 @@ The current buffer is given by BUFFER."
                                      4 erc-server-send-ping-interval
                                      #'erc-server-send-ping
                                      buffer))
-      (setq erc-server-ping-timer-alist (cons (cons buffer
-                                                    erc-server-ping-handler)
-                                              erc-server-ping-timer-alist)))))
+
+      ;; I check the timer alist for an existing timer. If one exists,
+      ;; I get rid of it
+      (let ((timer-tuple (assq buffer erc-server-ping-timer-alist)))
+        (if timer-tuple
+            ;; this buffer already has a timer. Cancel it and set the new one
+            (progn
+              (erc-cancel-timer (cdr timer-tuple))
+              (setf (cdr (assq buffer erc-server-ping-timer-alist)) 
erc-server-ping-handler))
+
+          ;; no existing timer for this buffer. Add new one
+          (add-to-list 'erc-server-ping-timer-alist
+                       (cons buffer erc-server-ping-handler)))))))
 
 (defun erc-server-process-alive (&optional buffer)
   "Return non-nil when BUFFER has an `erc-server-process' open or running."
-- 
2.0.0


reply via email to

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