unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dima Kogan <dima@secretsauce.net>
To: 19292@debbugs.gnu.org
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	[thread overview]
Message-ID: <87egsc4cnq.fsf@secretsauce.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 428 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-erc-server-ping-timer-alist-now-has-at-most-one-time.patch --]
[-- Type: text/x-diff, Size: 2138 bytes --]

From 421c00345c3407fff7044092c458316c6da870a6 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
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	other threads:[~2014-12-06 22:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-06 22:49 Dima Kogan [this message]
     [not found] ` <handler.19292.B.1417906179802.ack@debbugs.gnu.org>
2015-02-15 20:03   ` bug#19292: 24.3; [PATCH] erc-server-ping-timer-alist now has at most one timer per buffer Dima Kogan
2015-12-27 20:19 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87egsc4cnq.fsf@secretsauce.net \
    --to=dima@secretsauce.net \
    --cc=19292@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).