From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Fwd: HTTP redirects make url-retrieve-synchronously asynchronous Date: Mon, 23 Jan 2006 15:38:40 -0500 Message-ID: References: <87y81ep6wf.fsf-monnier+emacs@gnu.org> <87wtgu8trl.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1138050580 5311 80.91.229.2 (23 Jan 2006 21:09:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2006 21:09:40 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 23 22:09:36 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 1F18wI-0004sB-VW for ged-emacs-devel@m.gmane.org; Mon, 23 Jan 2006 22:09:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F18yx-0005oI-H2 for ged-emacs-devel@m.gmane.org; Mon, 23 Jan 2006 16:12:11 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F18Ve-0007db-87 for emacs-devel@gnu.org; Mon, 23 Jan 2006 15:41:54 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F18Vc-0007bt-52 for emacs-devel@gnu.org; Mon, 23 Jan 2006 15:41:53 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F18VH-0007Ct-HS for emacs-devel@gnu.org; Mon, 23 Jan 2006 15:41:34 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1F18a4-00030V-OI for emacs-devel@gnu.org; Mon, 23 Jan 2006 15:46:28 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id A82DD2CE9BE; Mon, 23 Jan 2006 15:38:45 -0500 (EST) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id B55D24AC015; Mon, 23 Jan 2006 15:38:40 -0500 (EST) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id 91B08E6C1E; Mon, 23 Jan 2006 15:38:40 -0500 (EST) Original-To: Mark Plaksin In-Reply-To: (Stefan Monnier's message of "Mon, 23 Jan 2006 11:40:33 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-4.854, requis 5, autolearn=not spam, AWL 0.05, BAYES_00 -4.90) X-MailScanner-From: monnier@iro.umontreal.ca 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:49457 Archived-At: >> 2. sometimes the callback gets called in another buffer than the one >> returned by url-retrieve. >> One solution would be to give the first buffer a local variable that >> would, in this case, point to the second buffer. >> Then url-retrieve-synchronously could check the local variable, which >> would tell it to check the process in the other buffer. > Yes, sounds like a good quick-fix. The patch below uses this approach. Mark, does it work well for you? Stefan Index: lisp/url/url.el =================================================================== RCS file: /sources/emacs/emacs/lisp/url/url.el,v retrieving revision 1.20 diff -u -r1.20 url.el --- lisp/url/url.el 10 Jan 2006 19:31:15 -0000 1.20 +++ lisp/url/url.el 23 Jan 2006 20:37:41 -0000 @@ -114,6 +114,13 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Retrieval functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defvar url-redirect-buffer nil + "New buffer into which the retrieval will take place. +Sometimes while retrieving a URL, the URL library needs to use another buffer +than the one returned initially by `url-retrieve'. In this case, it sets this +variable in the original buffer as a forwarding pointer.") + ;;;###autoload (defun url-retrieve (url callback &optional cbargs) "Retrieve URL asynchronously and call CALLBACK with CBARGS when finished. @@ -189,10 +189,14 @@ (url-debug 'retrieval "Spinning in url-retrieve-synchronously: %S (%S)" retrieval-done asynch-buffer) + (if (buffer-local-value 'url-redirect-buffer asynch-buffer) + (setq proc (get-buffer-process + (setq asynch-buffer + (buffer-local-value 'url-redirect-buffer + asynch-buffer)))) (if (and proc (memq (process-status proc) '(closed exit signal failed)) - ;; Make sure another process hasn't been started, as can - ;; happen with http redirections. + ;; Make sure another process hasn't been started. (eq proc (or (get-buffer-process asynch-buffer) proc))) ;; FIXME: It's not clear whether url-retrieve's callback is ;; guaranteed to be called or not. It seems that url-http @@ -200,7 +204,7 @@ ;; clear that it's a bug, but even then we need to decide how ;; url-http can then warn us that the download has completed. ;; In the mean time, we use this here workaround. - (setq retrieval-done t) + (setq retrieval-done t)) ;; We used to use `sit-for' here, but in some cases it wouldn't ;; work because apparently pending keyboard input would always ;; interrupt it before it got a chance to handle process input. Index: lisp/url/url-http.el =================================================================== RCS file: /sources/emacs/emacs/lisp/url/url-http.el,v retrieving revision 1.23 diff -u -r1.23 url-http.el --- lisp/url/url-http.el 18 Nov 2005 16:55:54 -0000 1.23 +++ lisp/url/url-http.el 23 Jan 2006 20:37:41 -0000 @@ -1,6 +1,6 @@ ;;; url-http.el --- HTTP retrieval routines -;; Copyright (C) 1999, 2001, 2004, 2005 Free Software Foundation, Inc. +;; Copyright (C) 1999, 2001, 2004, 2005, 2006 Free Software Foundation, Inc. ;; Author: Bill Perry ;; Keywords: comm, data, processes @@ -35,10 +35,8 @@ (require 'url-cookie) (require 'mail-parse) (require 'url-auth) -(autoload 'url-retrieve-synchronously "url") -(autoload 'url-retrieve "url") +(require 'url) (autoload 'url-cache-create-filename "url-cache") -(autoload 'url-mark-buffer-as-dead "url") (defconst url-http-default-port 80 "Default HTTP port.") (defconst url-http-asynchronous-p t "HTTP retrievals are asynchronous.") @@ -509,10 +509,17 @@ (let ((url-request-method url-http-method) (url-request-data url-http-data) (url-request-extra-headers url-http-extra-headers)) + ;; Put in the current buffer a forwarding pointer to the new + ;; destination buffer. + ;; FIXME: This is a hack to fix url-retrieve-synchronously + ;; without changing the API. Instead url-retrieve should + ;; either simply not return the "destination" buffer, or it + ;; should take an optional `dest-buf' argument. + (set (make-local-variable 'url-redirect-buffer) (url-retrieve redirect-uri url-callback-function (cons :redirect (cons redirect-uri - url-callback-arguments))) + url-callback-arguments)))) (url-mark-buffer-as-dead (current-buffer)))))) (4 ; Client error ;; 400 Bad Request