[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Erc-commit] [commit][emacs22] Implement limiting of reconnect attempts
From: |
mwolson |
Subject: |
[Erc-commit] [commit][emacs22] Implement limiting of reconnect attempts |
Date: |
Sun, 14 Oct 2007 00:48:36 -0400 |
commit b5d3beecc728b7d769fa8cd08ce70e817d4f5b94
Author: Michael Olson <address@hidden>
Date: Wed Dec 27 01:48:48 2006 +0000
Implement limiting of reconnect attempts
* erc-backend.el (erc-server-reconnect-count): New server variable that
keeps track of reconnection attempts.
(erc-server-reconnect-attempts): New option that determines the number
of reconnection attempts that ERC will make per server.
(erc-server-reconnect-timeout): New option that determines the amount
of time, in seconds, that ERC will wait between successive reconnect
attempts
(erc-server-reconnect): Move additional commands from
erc-process-sentinel-1 here.
(erc-server-reconnect-p): Make this a defsubst, since I'm worried about
the current buffer changing from underneath us. Implement limit of
number of reconnect attempts.
(erc-process-sentinel-1): If we have been disconnected, loop until we
either reconnect or run out of attempts.
* erc.el (erc-cmd-RECONNECT): Make this its own function, instead of just
an alias, since we should reset the reconnect count here.
git-archimport-id: address@hidden/erc--main--0--patch-73
diff --git a/ChangeLog b/ChangeLog
index c030889..5351d63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,23 @@
2006-12-27 Michael Olson <address@hidden>
- * erc.el (erc-cmd-RECONNECT): New command which is an alias to
+ * erc.el (erc-cmd-RECONNECT): New command that calls
erc-server-reconnect.
- * erc-backend.el (erc-server-reconnect): New function that
- reestablishes the current IRC connection.
- (erc-process-sentinel-1): Use it.
- (erc-server-reconnect-p): Move higher.
+ * erc-backend.el (erc-server-reconnect-count): New server variable
+ that keeps track of reconnection attempts.
+ (erc-server-reconnect-attempts): New option that determines the
+ number of reconnection attempts that ERC will make per server.
+ (erc-server-reconnect-timeout): New option that determines the
+ amount of time, in seconds, that ERC will wait between successive
+ reconnect attempts
+ (erc-server-reconnect): New function that reestablishes the
+ current IRC connection. Move some commands from
+ erc-process-sentinel-1 here.
+ (erc-process-sentinel-1): If we have been disconnected, loop until
+ we either reconnect or run out of attempts.
+ (erc-server-reconnect-p): Move higher and make this a defsubst,
+ since I'm worried about the current buffer changing from
+ underneath us. Implement limit of number of reconnect attempts..
* erc.texi (Getting Started): Update for /RECONNECT command.
diff --git a/erc-backend.el b/erc-backend.el
index 67cc21a..3f653a1 100644
--- a/erc-backend.el
+++ b/erc-backend.el
@@ -185,6 +185,10 @@ If you wish to determine whether an IRC connection is
currently
active, use the `erc-server-process-alive' function instead.")
(make-variable-buffer-local 'erc-server-connected)
+(defvar erc-server-reconnect-count 0
+ "Number of times we have failed to reconnect to the current server.")
+(make-variable-buffer-local 'erc-server-reconnect-count)
+
(defvar erc-server-quitting nil
"Non-nil if the user requests a quit.")
(make-variable-buffer-local 'erc-server-quitting)
@@ -278,6 +282,23 @@ Reconnection will happen automatically for any unexpected
disconnection."
:group 'erc-server
:type 'boolean)
+(defcustom erc-server-reconnect-attempts 2
+ "The number of times that ERC will attempt to reestablish a
+broken connection, or t to always attempt to reconnect.
+
+This only has an effect if `erc-server-auto-reconnect' is non-nil."
+ :group 'erc-server
+ :type '(choice (const :tag "Always reconnect" t)
+ integer))
+
+(defcustom erc-server-reconnect-timeout 1
+ "The amount of time, in seconds, that ERC will wait between
+successive reconnect attempts.
+
+If a key is pressed while ERC is waiting, it will stop waiting."
+ :group 'erc-server
+ :type 'number)
+
(defcustom erc-split-line-length 440
"*The maximum length of a single message.
If a message exceeds this size, it is broken into multiple ones.
@@ -508,6 +529,10 @@ Make sure you are in an ERC buffer when running this."
(buffer-live-p server))
(error "Couldn't switch to server buffer"))
(with-current-buffer server
+ (erc-update-mode-line)
+ (erc-set-active-buffer (current-buffer))
+ (setq erc-server-last-sent-time 0)
+ (setq erc-server-lines-sent 0)
(erc-open erc-session-server erc-session-port erc-server-current-nick
erc-session-user-full-name t erc-session-password))))
@@ -540,11 +565,16 @@ Make sure you are in an ERC buffer when running this."
(match-end 0))))
(erc-parse-server-response process line)))))))
-(defun erc-server-reconnect-p (event)
+(defsubst erc-server-reconnect-p (event)
"Return non-nil if ERC should attempt to reconnect automatically.
EVENT is the message received from the closed connection process."
(and erc-server-auto-reconnect
(not erc-server-banned)
+ ;; make sure we don't infinitely try to reconnect, unless the
+ ;; user wants that
+ (or (eq erc-server-reconnect-attempts t)
+ (and (integerp erc-server-reconnect-attempts)
+ (< erc-server-reconnect-count erc-server-reconnect-attempts)))
(or erc-server-timed-out
(not (string-match "^deleted" event)))
;; open-network-stream-nowait error for connection refused
@@ -562,19 +592,26 @@ Conditionally try to reconnect and take appropriate
action."
(set-buffer-modified-p nil)
(kill-buffer (current-buffer))))
;; unexpected disconnect
- (erc-display-message nil 'error (current-buffer)
- (if (erc-server-reconnect-p event)
- 'disconnected
- 'disconnected-noreconnect))
- (erc-update-mode-line)
- (erc-set-active-buffer (current-buffer))
- (setq erc-server-last-sent-time 0)
- (setq erc-server-lines-sent 0)
- (if (erc-server-reconnect-p event)
- (erc-server-reconnect)
- ;; terminate, do not reconnect
- (erc-display-message nil 'error (current-buffer)
- 'terminated ?e event))))
+ (let ((again t))
+ (while again
+ (setq again nil)
+ (erc-display-message nil 'error (current-buffer)
+ (if (erc-server-reconnect-p event)
+ 'disconnected
+ 'disconnected-noreconnect))
+ (if (erc-server-reconnect-p event)
+ (condition-case err
+ (progn
+ (erc-server-reconnect)
+ (setq erc-server-reconnect-count 0))
+ (error (when (integerp erc-server-reconnect-attempts)
+ (setq erc-server-reconnect-count
+ (1+ erc-server-reconnect-count))
+ (sit-for erc-server-reconnect-timeout)
+ (setq again t))))
+ ;; terminate, do not reconnect
+ (erc-display-message nil 'error (current-buffer)
+ 'terminated ?e event))))))
(defun erc-process-sentinel (cproc event)
"Sentinel function for ERC process."
diff --git a/erc.el b/erc.el
index 77d2faa..5aea199 100644
--- a/erc.el
+++ b/erc.el
@@ -3195,7 +3195,11 @@ the message given by REASON."
(defalias 'erc-cmd-GQ 'erc-cmd-GQUIT)
(put 'erc-cmd-GQUIT 'do-not-parse-args t)
-(defalias 'erc-cmd-RECONNECT 'erc-server-reconnect)
+(defun erc-cmd-RECONNECT ()
+ "Try to reconnect to the current IRC server."
+ (setq erc-server-reconnect-count 0)
+ (erc-server-reconnect)
+ t)
(defun erc-cmd-SERVER (server)
"Connect to SERVER, leaving existing connection intact."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Erc-commit] [commit][emacs22] Implement limiting of reconnect attempts,
mwolson <=