From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Victor Orlikowski Newsgroups: gmane.emacs.devel Subject: [PATCH] Allow ERC to re-connect in the background properly Date: Sun, 3 Feb 2019 17:43:30 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="54576"; mail-complaints-to="usenet@blaine.gmane.org" To: "emacs-devel@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 03 19:00:53 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gqM4b-000E51-Hc for ged-emacs-devel@m.gmane.org; Sun, 03 Feb 2019 19:00:53 +0100 Original-Received: from localhost ([127.0.0.1]:58774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqM4a-0003Hh-Fb for ged-emacs-devel@m.gmane.org; Sun, 03 Feb 2019 13:00:52 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqLoC-0001is-LS for emacs-devel@gnu.org; Sun, 03 Feb 2019 12:43:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqLo4-0001mT-VY for emacs-devel@gnu.org; Sun, 03 Feb 2019 12:43:53 -0500 Original-Received: from smtp-gw-17.oit.duke.edu ([152.3.189.243]:36790 helo=mail-gw-17.oit.duke.edu) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqLny-0001UQ-3P for emacs-devel@gnu.org; Sun, 03 Feb 2019 12:43:44 -0500 Original-Received: from smtpgw-04.oit.duke.edu (smtpgw-04.oit.duke.edu [10.136.225.89]) by mail-gw-17.oit.duke.edu (8.16.0.27/8.16.0.27) with ESMTPS id x13HhVAQ026203 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 3 Feb 2019 12:43:32 -0500 Original-Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01lp2051.outbound.protection.outlook.com [104.47.34.51]) by smtpgw-04.oit.duke.edu (8.16.0.27/8.16.0.27) with ESMTPS id x13HhUK3014173 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 3 Feb 2019 12:43:31 -0500 Original-Received: from CO2PR05MB2488.namprd05.prod.outlook.com (10.166.95.146) by CO2PR05MB2680.namprd05.prod.outlook.com (10.166.95.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1601.14; Sun, 3 Feb 2019 17:43:30 +0000 Original-Received: from CO2PR05MB2488.namprd05.prod.outlook.com ([fe80::b10c:f1aa:5c08:17f7]) by CO2PR05MB2488.namprd05.prod.outlook.com ([fe80::b10c:f1aa:5c08:17f7%2]) with mapi id 15.20.1601.013; Sun, 3 Feb 2019 17:43:30 +0000 Thread-Topic: [PATCH] Allow ERC to re-connect in the background properly Thread-Index: AQHUu+f5xQQAaj/umkOEkgOY148TJg== Accept-Language: en-US Content-Language: en-US x-originating-ip: [50.111.87.13] x-clientproxiedby: BN7PR10CA0024.namprd10.prod.outlook.com (2603:10b6:406:bc::37) To CO2PR05MB2488.namprd05.prod.outlook.com (2603:10b6:102:10::18) x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CO2PR05MB2680; 20:IQAf5TgNdHljCqoe7XPWFv2exrsp7LcJ4Vvka0YYKz496sYd+vS5lVpM/90M8/OiJAJ/fm+KalSMsLyOkdZesLuSjcDJ/nc4+1tn1fKyzS20YyX6iReL2dM5xiyTP5skIjV8XnFSq3vEob+nQfLDb7twiPDe6kC/M7XX+Q18RsQ= x-ms-office365-filtering-correlation-id: ff75da8c-5432-401a-7b9a-08d689ff1be1 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(2017052603328)(7153060)(7193020); SRVR:CO2PR05MB2680; x-ms-traffictypediagnostic: CO2PR05MB2680: x-microsoft-antispam-prvs: x-forefront-prvs: 0937FB07C5 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(7916004)(396003)(346002)(376002)(39860400002)(136003)(366004)(199004)(189003)(45914002)(71190400001)(478600001)(71200400001)(9686003)(7736002)(305945005)(14454004)(14444005)(75432002)(66066001)(97736004)(8676002)(256004)(3846002)(6116002)(81166006)(53546011)(2906002)(26005)(68736007)(81156014)(386003)(102836004)(53936002)(2351001)(186003)(6506007)(88552002)(8936002)(476003)(486006)(105586002)(106356001)(2501003)(6916009)(5640700003)(786003)(6436002)(33716001)(86362001)(316002)(33896004)(52116002)(6486002)(99286004)(25786009)(6512007); DIR:OUT; SFP:1102; SCL:1; SRVR:CO2PR05MB2680; H:CO2PR05MB2488.namprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: duke.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: kaRo0HSsz7zXpig1AlFQvScEMPetUeZH01LQwA0S3ykIqQtUR/Ol8N/PoCAbaSoRAw4CYIv9bEvAh0oTQHbgZQh3rgbybfUOqoWnHGz/oz0v+laZv4UQaoS56GrGaiPkCbzrNvB4mdDWkj1YcUFRxSsHnZLOwHbTtKVHXFgT5+D5wVnp/a629XllYS9piE8ods9jmh9xAyvJyWpdr3zNwzcmWRIHzS9ErimcWStk9KBFZJLqHUIaPd48RlKwzQ8c3CKCguvuj2JkNnJnepDAd9QgJKhArxOsV9x6OIB805LfaFE9TbnxQMPwwoJVicIQG8eQY6Vm9CQA+ElvNhUvJlLZhdxWkt61S+AUNQH2YSbblqd6YD4C+iBRHtBjdMPoFFKGz/HlhmSkTFokH+153v6KSkBXjJtLNWahndP3mes= X-OriginatorOrg: duke.edu X-MS-Exchange-CrossTenant-Network-Message-Id: ff75da8c-5432-401a-7b9a-08d689ff1be1 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2019 17:43:29.4860 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: cb72c54e-4a31-4d9e-b14a-1ea36dfac94c X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR05MB2680 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-03_08:, , signatures=0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-03_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=996 adultscore=0 classifier=spam adjust=-31 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902030147 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 152.3.189.243 X-Mailman-Approved-At: Sun, 03 Feb 2019 13:00:10 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:232938 Archived-At: In my experience, the existing code for re-connecting to a disconnected server forces ERC into the foreground. The following patch changes ERC so that reconnection attempts proceed in the background, without interrupting the user's workflow. >From 7a64c15406225a14dca6863342da3d90569baf49 Mon Sep 17 00:00:00 2001 From: "Victor J. Orlikowski" Date: Sun, 3 Feb 2019 12:32:12 -0500 Subject: [PATCH] Handle reconnection attempts in the background, rather tha= n forcing to the foreground. --- lisp/erc/erc-backend.el | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 2fd3d454bf..57f34073be 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -613,11 +613,6 @@ Make sure you are in an ERC buffer when running this." (erc-open erc-session-server erc-session-port erc-server-current-n= ick erc-session-user-full-name t erc-session-password))))) =20 -(defun erc-server-delayed-reconnect (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) @@ -667,6 +662,25 @@ EVENT is the message received from the closed connecti= on process." ;; open-network-stream-nowait error for connection refused (if (string-match "^failed with code 111" ,event) 'nonblocki= ng t)))))) =20 +(defun erc-server-background-reconnect (buffer) + (let ((process nil)) + (condition-case err + (progn + (setq erc-server-reconnecting nil + erc-server-reconnect-count (1+ erc-server-reconnect-count)= ) + (if (buffer-live-p buffer) + (with-current-buffer buffer + (setq process (get-buffer-process (erc-server-buffer))) + (erc-server-reconnect)))) + (error (unless (integerp erc-server-reconnect-attempts) + (message "%s ... %s" + "Reconnecting until we succeed" + "kill the ERC server buffer to stop")) + (run-at-time erc-server-reconnect-timeout nil + #'erc-server-background-reconnect buffer))) + (if process + (delete-process process)))) + (defun erc-process-sentinel-2 (event buffer) "Called when `erc-process-sentinel-1' has detected an unexpected disconn= ect." (if (not (buffer-live-p buffer)) @@ -684,18 +698,8 @@ EVENT is the message received from the closed connecti= on process." (erc-update-mode-line) (set-buffer-modified-p nil)) ;; reconnect - (condition-case nil - (progn - (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 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 buffer)))))))) + (run-at-time erc-server-reconnect-timeout nil + #'erc-server-background-reconnect buffer)))))) =20 (defun erc-process-sentinel-1 (event buffer) "Called when `erc-process-sentinel' has decided that we're disconnecting= . Best, Victor --=20 Victor J. Orlikowski <> vjo@(ee.|cs.)?duke.edu