From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Magnus Henoch Newsgroups: gmane.emacs.devel Subject: Re: url-retrieve may cause hang Date: Tue, 17 Oct 2006 16:57:16 +0200 Message-ID: <87vemj9eib.fsf@freemail.hu> References: <878xjfydq3.fsf@freemail.hu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1161097178 19309 80.91.229.2 (17 Oct 2006 14:59:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 17 Oct 2006 14:59:38 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 17 16:59:27 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GZqPN-0000lc-1b for ged-emacs-devel@m.gmane.org; Tue, 17 Oct 2006 16:59:09 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GZqPM-0001Ub-J4 for ged-emacs-devel@m.gmane.org; Tue, 17 Oct 2006 10:59:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GZqP4-0001Tj-A4 for emacs-devel@gnu.org; Tue, 17 Oct 2006 10:58:50 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GZqP0-0001Qq-TZ for emacs-devel@gnu.org; Tue, 17 Oct 2006 10:58:50 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GZqOz-0001Qa-To for emacs-devel@gnu.org; Tue, 17 Oct 2006 10:58:46 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GZqOy-0007Q8-Ss for emacs-devel@gnu.org; Tue, 17 Oct 2006 10:58:45 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GZqO6-0000Tk-Jq for emacs-devel@gnu.org; Tue, 17 Oct 2006 16:57:51 +0200 Original-Received: from etthundrat.olf.sgsnet.se ([193.11.222.85]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Oct 2006 16:57:50 +0200 Original-Received: from mange by etthundrat.olf.sgsnet.se with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Oct 2006 16:57:50 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-To: emacs-devel@gnu.org Original-Lines: 135 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: etthundrat.olf.sgsnet.se Mail-Copies-To: never Jabber-Id: legoscia@jabber.cd.chalmers.se User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (berkeley-unix) Cancel-Lock: sha1:mcqz0iQ6xKP68Mjw/eE3e162S18= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:60820 Archived-At: --=-=-= storm@cua.dk (Kim F. Storm) writes: > I doubt it is very tricky to do. > > You should check with (featurep 'make-network-process '(:nowait t)) > to see if non-blocking connect is possible, and fallback to > the current blocking code if not. > > Try making the change -- then we can look at the patches and judge > whether it is ok to install before the release (if it hasn't happened > before). I have attached my first attempt. There are two problems with it: - DNS lookups are still synchronous. It seems we would need an external library like GNU adns for that. - There is no protocol for letting the callback know that retrieval failed. Without this patch, the caller would immediately get an error, but now the error is signalled in the sentinel. One solution would be to introduce an :error argument to the callback, similar to the :redirect one. What do you think? Magnus --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=url-async.patch Index: url-gw.el =================================================================== RCS file: /sources/emacs/emacs/lisp/url/url-gw.el,v retrieving revision 1.13 diff -c -r1.13 url-gw.el *** url-gw.el 26 Apr 2006 20:40:18 -0000 1.13 --- url-gw.el 17 Oct 2006 14:03:41 -0000 *************** *** 210,216 **** (defun url-open-stream (name buffer host service) "Open a stream to HOST, possibly via a gateway. Args per `open-network-stream'. ! Will not make a connection if `url-gateway-unplugged' is non-nil." (unless url-gateway-unplugged (let ((gw-method (if (and url-gateway-local-host-regexp (not (eq 'tls url-gateway-method)) --- 210,217 ---- (defun url-open-stream (name buffer host service) "Open a stream to HOST, possibly via a gateway. Args per `open-network-stream'. ! Will not make a connection if `url-gateway-unplugged' is non-nil. ! Might do a non-blocking connection; use `process-status' to check." (unless url-gateway-unplugged (let ((gw-method (if (and url-gateway-local-host-regexp (not (eq 'tls url-gateway-method)) *************** *** 249,255 **** (ssl (open-ssl-stream name buffer host service)) ((native) ! (open-network-stream name buffer host service)) (socks (socks-open-network-stream name buffer host service)) (telnet --- 250,260 ---- (ssl (open-ssl-stream name buffer host service)) ((native) ! ;; Use non-blocking socket if we can. ! (make-network-process :name name :buffer buffer ! :host host :service service ! :nowait ! (featurep 'make-network-process '(:nowait t)))) (socks (socks-open-network-stream name buffer host service)) (telnet Index: url-http.el =================================================================== RCS file: /sources/emacs/emacs/lisp/url/url-http.el,v retrieving revision 1.35 diff -c -r1.35 url-http.el *** url-http.el 16 Oct 2006 14:28:46 -0000 1.35 --- url-http.el 17 Oct 2006 14:03:42 -0000 *************** *** 1089,1099 **** url-current-object)) (set-process-buffer connection buffer) - (set-process-sentinel connection 'url-http-end-of-document-sentinel) (set-process-filter connection 'url-http-generic-filter) ! (process-send-string connection (url-http-create-request url)))) buffer)) ;; Since Emacs 19/20 does not allow you to change the ;; `after-change-functions' hook in the midst of running them, we fake ;; an after change by hooking into the process filter and inserting --- 1089,1120 ---- url-current-object)) (set-process-buffer connection buffer) (set-process-filter connection 'url-http-generic-filter) ! (let ((status (process-status connection))) ! (cond ! ((eq status 'connect) ! ;; Asynchronous connection ! (set-process-sentinel connection 'url-http-async-sentinel)) ! ((eq status 'failed) ! ;; Asynchronous connection failed ! (error "Could not create connection to %s:%d" (url-host url) ! (url-port url))) ! (t ! (set-process-sentinel connection 'url-http-end-of-document-sentinel) ! (process-send-string connection (url-http-create-request url))))))) buffer)) + (defun url-http-async-sentinel (proc why) + (with-current-buffer (process-buffer proc) + (cond + ((string= (substring why 0 4) "open") + (set-process-sentinel proc 'url-http-end-of-document-sentinel) + (process-send-string proc (url-http-create-request url-current-object))) + (t + ;; XXX: should the callback get this error? + (error "Could not create connection to %s:%d" (url-host url-current-object) + (url-port url-current-object)))))) + ;; Since Emacs 19/20 does not allow you to change the ;; `after-change-functions' hook in the midst of running them, we fake ;; an after change by hooking into the process filter and inserting --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--