aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorl3thal2015-11-13 16:37:26 -0500
committerl3thal2015-11-13 16:37:26 -0500
commit51644c33d2e046b681646e2e07a636ba2fb234dc (patch)
tree48288c32e5276c8f6c5352e57cb961d0abfdeb9b
parent84c7b3879c7a720693064bc5057fcb8f218235ad (diff)
parent68cdc4bd7a780641a45b53b8fb71431e2da1a058 (diff)
downloademacs-51644c33d2e046b681646e2e07a636ba2fb234dc.tar.gz
emacs-51644c33d2e046b681646e2e07a636ba2fb234dc.zip
Merge branch 'erc-async-reconnect' into emacs-25
-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."
376 :type '(repeat (cons (string :tag "Target") 376 :type '(repeat (cons (string :tag "Target")
377 coding-system))) 377 coding-system)))
378 378
379(defcustom erc-server-connect-function 'open-network-stream 379(defcustom erc-server-connect-function 'erc-open-network-stream
380 "Function used to initiate a connection. 380 "Function used to initiate a connection.
381It should take same arguments as `open-network-stream' does." 381It should take same arguments as `open-network-stream' does."
382 :group 'erc-server 382 :group 'erc-server
@@ -505,6 +505,10 @@ The current buffer is given by BUFFER."
505 (memq (process-status erc-server-process) '(run open))))) 505 (memq (process-status erc-server-process) '(run open)))))
506 506
507;;;; Connecting to a server 507;;;; Connecting to a server
508(defun erc-open-network-stream (name buffer host service)
509 "As `open-network-stream', but does non-blocking IO"
510 (make-network-process :name name :buffer buffer
511 :host host :service service :nowait t))
508 512
509(defun erc-server-connect (server port buffer) 513(defun erc-server-connect (server port buffer)
510 "Perform the connection and login using the specified SERVER and PORT. 514 "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."
565 (setq erc-server-last-sent-time 0) 569 (setq erc-server-last-sent-time 0)
566 (setq erc-server-lines-sent 0) 570 (setq erc-server-lines-sent 0)
567 (let ((erc-server-connect-function (or erc-session-connector 571 (let ((erc-server-connect-function (or erc-session-connector
568 'open-network-stream))) 572 'erc-open-network-stream)))
569 (erc-open erc-session-server erc-session-port erc-server-current-nick 573 (erc-open erc-session-server erc-session-port erc-server-current-nick
570 erc-session-user-full-name t erc-session-password))))) 574 erc-session-user-full-name t erc-session-password)))))
571 575
576(defun erc-server-delayed-reconnect (event buffer)
577 (if (buffer-live-p buffer)
578 (with-current-buffer buffer
579 (erc-server-reconnect))))
580
572(defun erc-server-filter-function (process string) 581(defun erc-server-filter-function (process string)
573 "The process filter for the ERC server." 582 "The process filter for the ERC server."
574 (with-current-buffer (process-buffer process) 583 (with-current-buffer (process-buffer process)
@@ -615,17 +624,16 @@ EVENT is the message received from the closed connection process."
615 (or erc-server-timed-out 624 (or erc-server-timed-out
616 (not (string-match "^deleted" event))) 625 (not (string-match "^deleted" event)))
617 ;; open-network-stream-nowait error for connection refused 626 ;; open-network-stream-nowait error for connection refused
618 (not (string-match "^failed with code 111" event))))) 627 (if (string-match "^failed with code 111" event) 'nonblocking t))))
619 628
620(defun erc-process-sentinel-2 (event buffer) 629(defun erc-process-sentinel-2 (event buffer)
621 "Called when `erc-process-sentinel-1' has detected an unexpected disconnect." 630 "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
622 (if (not (buffer-live-p buffer)) 631 (if (not (buffer-live-p buffer))
623 (erc-update-mode-line) 632 (erc-update-mode-line)
624 (with-current-buffer buffer 633 (with-current-buffer buffer
625 (let ((reconnect-p (erc-server-reconnect-p event))) 634 (let ((reconnect-p (erc-server-reconnect-p event)) message delay)
626 (erc-display-message nil 'error (current-buffer) 635 (setq message (if reconnect-p 'disconnected 'disconnected-noreconnect))
627 (if reconnect-p 'disconnected 636 (erc-display-message nil 'error (current-buffer) message)
628 'disconnected-noreconnect))
629 (if (not reconnect-p) 637 (if (not reconnect-p)
630 ;; terminate, do not reconnect 638 ;; terminate, do not reconnect
631 (progn 639 (progn
@@ -637,23 +645,16 @@ EVENT is the message received from the closed connection process."
637 ;; reconnect 645 ;; reconnect
638 (condition-case err 646 (condition-case err
639 (progn 647 (progn
640 (setq erc-server-reconnecting nil) 648 (setq erc-server-reconnecting nil
641 (erc-server-reconnect) 649 erc-server-reconnect-count (1+ erc-server-reconnect-count))
642 (setq erc-server-reconnect-count 0)) 650 (setq delay erc-server-reconnect-timeout)
643 (error (when (buffer-live-p buffer) 651 (run-at-time delay nil
644 (set-buffer buffer) 652 #'erc-server-delayed-reconnect event buffer))
645 (if (integerp erc-server-reconnect-attempts) 653 (error (unless (integerp erc-server-reconnect-attempts)
646 (setq erc-server-reconnect-count 654 (message "%s ... %s"
647 (1+ erc-server-reconnect-count)) 655 "Reconnecting until we succeed"
648 (message "%s ... %s" 656 "kill the ERC server buffer to stop"))
649 "Reconnecting until we succeed" 657 (erc-server-delayed-reconnect event buffer))))))))
650 "kill the ERC server buffer to stop"))
651 (if (numberp erc-server-reconnect-timeout)
652 (run-at-time erc-server-reconnect-timeout nil
653 #'erc-process-sentinel-2
654 event buffer)
655 (error (concat "`erc-server-reconnect-timeout'"
656 " must be a number")))))))))))
657 658
658(defun erc-process-sentinel-1 (event buffer) 659(defun erc-process-sentinel-1 (event buffer)
659 "Called when `erc-process-sentinel' has decided that we're disconnecting. 660 "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."
1963 (erc-update-modules) 1963 (erc-update-modules)
1964 (set-buffer buffer) 1964 (set-buffer buffer)
1965 (setq old-point (point)) 1965 (setq old-point (point))
1966 (erc-mode) 1966 (let ((old-recon-count erc-server-reconnect-count))
1967 (erc-mode)
1968 (setq erc-server-reconnect-count old-recon-count))
1967 (setq erc-server-announced-name server-announced-name) 1969 (setq erc-server-announced-name server-announced-name)
1968 (setq erc-server-connected connected-p) 1970 (setq erc-server-connected connected-p)
1969 ;; connection parameters 1971 ;; connection parameters
@@ -2203,6 +2205,7 @@ Arguments are the same as for `erc'."
2203The process will be given the name NAME, its target buffer will be 2205The process will be given the name NAME, its target buffer will be
2204BUFFER. HOST and PORT specify the connection target." 2206BUFFER. HOST and PORT specify the connection target."
2205 (open-network-stream name buffer host port 2207 (open-network-stream name buffer host port
2208 :nowait t
2206 :type 'tls)) 2209 :type 'tls))
2207 2210
2208;;; Displaying error messages 2211;;; Displaying error messages
@@ -4483,6 +4486,7 @@ Set user modes and run `erc-after-connect' hook."
4483 (nick (car (erc-response.command-args parsed))) 4486 (nick (car (erc-response.command-args parsed)))
4484 (buffer (process-buffer proc))) 4487 (buffer (process-buffer proc)))
4485 (setq erc-server-connected t) 4488 (setq erc-server-connected t)
4489 (setq erc-server-reconnect-count 0)
4486 (erc-update-mode-line) 4490 (erc-update-mode-line)
4487 (erc-set-initial-user-mode nick buffer) 4491 (erc-set-initial-user-mode nick buffer)
4488 (erc-server-setup-periodical-ping buffer) 4492 (erc-server-setup-periodical-ping buffer)