summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorl3thal <kwhite@gnu.org>2015-11-13 16:37:26 -0500
committerl3thal <kwhite@gnu.org>2015-11-13 16:37:26 -0500
commit51644c33d2e046b681646e2e07a636ba2fb234dc (patch)
tree48288c32e5276c8f6c5352e57cb961d0abfdeb9b /lisp
parent84c7b3879c7a720693064bc5057fcb8f218235ad (diff)
parent68cdc4bd7a780641a45b53b8fb71431e2da1a058 (diff)
downloademacs-51644c33d2e046b681646e2e07a636ba2fb234dc.tar.gz
Merge branch 'erc-async-reconnect' into emacs-25
Diffstat (limited to 'lisp')
-rw-r--r--lisp/erc/erc-backend.el49
-rw-r--r--lisp/erc/erc.el6
2 files changed, 30 insertions, 25 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index ec45dcfcf24..755443f8a94 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -376,7 +376,7 @@ alist."
:type '(repeat (cons (string :tag "Target")
coding-system)))
-(defcustom erc-server-connect-function 'open-network-stream
+(defcustom erc-server-connect-function 'erc-open-network-stream
"Function used to initiate a connection.
It should take same arguments as `open-network-stream' does."
:group 'erc-server
@@ -505,6 +505,10 @@ The current buffer is given by BUFFER."
(memq (process-status erc-server-process) '(run open)))))
;;;; Connecting to a server
+(defun erc-open-network-stream (name buffer host service)
+ "As `open-network-stream', but does non-blocking IO"
+ (make-network-process :name name :buffer buffer
+ :host host :service service :nowait t))
(defun erc-server-connect (server port buffer)
"Perform the connection and login using the specified SERVER and PORT.
@@ -565,10 +569,15 @@ Make sure you are in an ERC buffer when running this."
(setq erc-server-last-sent-time 0)
(setq erc-server-lines-sent 0)
(let ((erc-server-connect-function (or erc-session-connector
- 'open-network-stream)))
+ 'erc-open-network-stream)))
(erc-open erc-session-server erc-session-port erc-server-current-nick
erc-session-user-full-name t erc-session-password)))))
+(defun erc-server-delayed-reconnect (event buffer)
+ (if (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (erc-server-reconnect))))
+
(defun erc-server-filter-function (process string)
"The process filter for the ERC server."
(with-current-buffer (process-buffer process)
@@ -615,17 +624,16 @@ EVENT is the message received from the closed connection process."
(or erc-server-timed-out
(not (string-match "^deleted" event)))
;; open-network-stream-nowait error for connection refused
- (not (string-match "^failed with code 111" event)))))
+ (if (string-match "^failed with code 111" event) 'nonblocking t))))
(defun erc-process-sentinel-2 (event buffer)
"Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
(if (not (buffer-live-p buffer))
(erc-update-mode-line)
(with-current-buffer buffer
- (let ((reconnect-p (erc-server-reconnect-p event)))
- (erc-display-message nil 'error (current-buffer)
- (if reconnect-p 'disconnected
- 'disconnected-noreconnect))
+ (let ((reconnect-p (erc-server-reconnect-p event)) message delay)
+ (setq message (if reconnect-p 'disconnected 'disconnected-noreconnect))
+ (erc-display-message nil 'error (current-buffer) message)
(if (not reconnect-p)
;; terminate, do not reconnect
(progn
@@ -637,23 +645,16 @@ EVENT is the message received from the closed connection process."
;; reconnect
(condition-case err
(progn
- (setq erc-server-reconnecting nil)
- (erc-server-reconnect)
- (setq erc-server-reconnect-count 0))
- (error (when (buffer-live-p buffer)
- (set-buffer buffer)
- (if (integerp erc-server-reconnect-attempts)
- (setq erc-server-reconnect-count
- (1+ erc-server-reconnect-count))
- (message "%s ... %s"
- "Reconnecting until we succeed"
- "kill the ERC server buffer to stop"))
- (if (numberp erc-server-reconnect-timeout)
- (run-at-time erc-server-reconnect-timeout nil
- #'erc-process-sentinel-2
- event buffer)
- (error (concat "`erc-server-reconnect-timeout'"
- " must be a number")))))))))))
+ (setq erc-server-reconnecting nil
+ erc-server-reconnect-count (1+ erc-server-reconnect-count))
+ (setq delay erc-server-reconnect-timeout)
+ (run-at-time delay nil
+ #'erc-server-delayed-reconnect event buffer))
+ (error (unless (integerp erc-server-reconnect-attempts)
+ (message "%s ... %s"
+ "Reconnecting until we succeed"
+ "kill the ERC server buffer to stop"))
+ (erc-server-delayed-reconnect event buffer))))))))
(defun erc-process-sentinel-1 (event buffer)
"Called when `erc-process-sentinel' has decided that we're disconnecting.
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 8e26db1d9d3..d82089f5b05 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1963,7 +1963,9 @@ Returns the buffer for the given server or channel."
(erc-update-modules)
(set-buffer buffer)
(setq old-point (point))
- (erc-mode)
+ (let ((old-recon-count erc-server-reconnect-count))
+ (erc-mode)
+ (setq erc-server-reconnect-count old-recon-count))
(setq erc-server-announced-name server-announced-name)
(setq erc-server-connected connected-p)
;; connection parameters
@@ -2203,6 +2205,7 @@ Arguments are the same as for `erc'."
The process will be given the name NAME, its target buffer will be
BUFFER. HOST and PORT specify the connection target."
(open-network-stream name buffer host port
+ :nowait t
:type 'tls))
;;; Displaying error messages
@@ -4483,6 +4486,7 @@ Set user modes and run `erc-after-connect' hook."
(nick (car (erc-response.command-args parsed)))
(buffer (process-buffer proc)))
(setq erc-server-connected t)
+ (setq erc-server-reconnect-count 0)
(erc-update-mode-line)
(erc-set-initial-user-mode nick buffer)
(erc-server-setup-periodical-ping buffer)