diff options
| author | Vivek Dasmohapatra | 2015-12-27 23:12:30 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2015-12-27 23:12:30 +0100 |
| commit | 92e1878a04a7940413c426d641334dd8f090f741 (patch) | |
| tree | e83ea30bd6439c86b59f2eb74b12b3427d1ae8f5 | |
| parent | 507e98a54d1aa37823c64993d6b59257a82fe8f4 (diff) | |
| download | emacs-92e1878a04a7940413c426d641334dd8f090f741.tar.gz emacs-92e1878a04a7940413c426d641334dd8f090f741.zip | |
Make erc connect asynchronously
* lisp/erc/erc-backend.el (erc-server-reconnect): Use it to
reconnect asynchronously.
* lisp/erc/erc-backend.el (erc-open-network-stream): New function (bug#5650).
| -rw-r--r-- | lisp/erc/erc-backend.el | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index ec45dcfcf24..a0b3537afee 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. |
| 381 | It should take same arguments as `open-network-stream' does." | 381 | It should take same arguments as `open-network-stream' does." |
| 382 | :group 'erc-server | 382 | :group 'erc-server |
| @@ -505,51 +505,53 @@ 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. |
| 511 | We will store server variables in the buffer given by BUFFER." | 515 | We will store server variables in the buffer given by BUFFER." |
| 512 | (let ((msg (erc-format-message 'connect ?S server ?p port))) | 516 | (let ((msg (erc-format-message 'connect ?S server ?p port)) process) |
| 513 | (message "%s" msg) | 517 | (message "%s" msg) |
| 514 | (let ((process (funcall erc-server-connect-function | 518 | (setq process (funcall erc-server-connect-function |
| 515 | (format "erc-%s-%s" server port) | 519 | (format "erc-%s-%s" server port) nil server port)) |
| 516 | nil server port))) | 520 | (unless (processp process) |
| 517 | (unless (processp process) | 521 | (error "Connection attempt failed")) |
| 518 | (error "Connection attempt failed")) | 522 | ;; Misc server variables |
| 523 | (with-current-buffer buffer | ||
| 524 | (setq erc-server-process process) | ||
| 525 | (setq erc-server-quitting nil) | ||
| 526 | (setq erc-server-reconnecting nil) | ||
| 527 | (setq erc-server-timed-out nil) | ||
| 528 | (setq erc-server-banned nil) | ||
| 529 | (setq erc-server-error-occurred nil) | ||
| 530 | (let ((time (erc-current-time))) | ||
| 531 | (setq erc-server-last-sent-time time) | ||
| 532 | (setq erc-server-last-ping-time time) | ||
| 533 | (setq erc-server-last-received-time time)) | ||
| 534 | (setq erc-server-lines-sent 0) | ||
| 535 | ;; last peers (sender and receiver) | ||
| 536 | (setq erc-server-last-peers '(nil . nil))) | ||
| 537 | ;; we do our own encoding and decoding | ||
| 538 | (when (fboundp 'set-process-coding-system) | ||
| 539 | (set-process-coding-system process 'raw-text)) | ||
| 540 | ;; process handlers | ||
| 541 | (set-process-sentinel process 'erc-process-sentinel) | ||
| 542 | (set-process-filter process 'erc-server-filter-function) | ||
| 543 | (set-process-buffer process buffer) | ||
| 544 | (erc-log "\n\n\n********************************************\n") | ||
| 545 | (message "%s" (erc-format-message | ||
| 546 | 'login ?n | ||
| 547 | (with-current-buffer buffer (erc-current-nick)))) | ||
| 548 | ;; wait with script loading until we receive a confirmation (first | ||
| 549 | ;; MOTD line) | ||
| 550 | (if (eq (process-status process) 'connect) | ||
| 551 | ;; waiting for a non-blocking connect - keep the user informed | ||
| 552 | (erc-display-message nil nil buffer "Opening connection..\n") | ||
| 519 | (message "%s...done" msg) | 553 | (message "%s...done" msg) |
| 520 | ;; Misc server variables | 554 | (erc-login)) )) |
| 521 | (with-current-buffer buffer | ||
| 522 | (setq erc-server-process process) | ||
| 523 | (setq erc-server-quitting nil) | ||
| 524 | (setq erc-server-reconnecting nil) | ||
| 525 | (setq erc-server-timed-out nil) | ||
| 526 | (setq erc-server-banned nil) | ||
| 527 | (setq erc-server-error-occurred nil) | ||
| 528 | (let ((time (erc-current-time))) | ||
| 529 | (setq erc-server-last-sent-time time) | ||
| 530 | (setq erc-server-last-ping-time time) | ||
| 531 | (setq erc-server-last-received-time time)) | ||
| 532 | (setq erc-server-lines-sent 0) | ||
| 533 | ;; last peers (sender and receiver) | ||
| 534 | (setq erc-server-last-peers '(nil . nil))) | ||
| 535 | ;; we do our own encoding and decoding | ||
| 536 | (when (fboundp 'set-process-coding-system) | ||
| 537 | (set-process-coding-system process 'raw-text)) | ||
| 538 | ;; process handlers | ||
| 539 | (set-process-sentinel process 'erc-process-sentinel) | ||
| 540 | (set-process-filter process 'erc-server-filter-function) | ||
| 541 | (set-process-buffer process buffer))) | ||
| 542 | (erc-log "\n\n\n********************************************\n") | ||
| 543 | (message "%s" (erc-format-message | ||
| 544 | 'login ?n | ||
| 545 | (with-current-buffer buffer (erc-current-nick)))) | ||
| 546 | ;; wait with script loading until we receive a confirmation (first | ||
| 547 | ;; MOTD line) | ||
| 548 | (if (eq erc-server-connect-function 'open-network-stream-nowait) | ||
| 549 | ;; it's a bit unclear otherwise that it's attempting to establish a | ||
| 550 | ;; connection | ||
| 551 | (erc-display-message nil nil buffer "Opening connection..\n") | ||
| 552 | (erc-login))) | ||
| 553 | 555 | ||
| 554 | (defun erc-server-reconnect () | 556 | (defun erc-server-reconnect () |
| 555 | "Reestablish the current IRC connection. | 557 | "Reestablish the current IRC connection. |
| @@ -565,7 +567,7 @@ Make sure you are in an ERC buffer when running this." | |||
| 565 | (setq erc-server-last-sent-time 0) | 567 | (setq erc-server-last-sent-time 0) |
| 566 | (setq erc-server-lines-sent 0) | 568 | (setq erc-server-lines-sent 0) |
| 567 | (let ((erc-server-connect-function (or erc-session-connector | 569 | (let ((erc-server-connect-function (or erc-session-connector |
| 568 | 'open-network-stream))) | 570 | 'erc-open-network-stream))) |
| 569 | (erc-open erc-session-server erc-session-port erc-server-current-nick | 571 | (erc-open erc-session-server erc-session-port erc-server-current-nick |
| 570 | erc-session-user-full-name t erc-session-password))))) | 572 | erc-session-user-full-name t erc-session-password))))) |
| 571 | 573 | ||