mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-13 16:38:14 +00:00
`url-retrieve-synchronously' now takes an optional timeout parameter
* doc/misc/url.texi (Retrieving URLs): Document optional parameters. * lisp/url/url.el (url-retrieve-synchronously): Allow passing in a timeout parameter (bug#22940).
This commit is contained in:
parent
4f25bef332
commit
77ba0f1c5a
@ -289,11 +289,16 @@ string or a parsed URL structure. If it is a string, that string is
|
|||||||
passed through @code{url-encode-url} before using it, to ensure that
|
passed through @code{url-encode-url} before using it, to ensure that
|
||||||
it is properly URI-encoded (@pxref{URI Encoding}).
|
it is properly URI-encoded (@pxref{URI Encoding}).
|
||||||
|
|
||||||
@defun url-retrieve-synchronously url
|
@defun url-retrieve-synchronously url &optional silent no-cookies timeout
|
||||||
This function synchronously retrieves the data specified by @var{url},
|
This function synchronously retrieves the data specified by @var{url},
|
||||||
and returns a buffer containing the data. The return value is
|
and returns a buffer containing the data. The return value is
|
||||||
@code{nil} if there is no data associated with the URL (as is the case
|
@code{nil} if there is no data associated with the URL (as is the case
|
||||||
for @code{dired}, @code{info}, and @code{mailto} URLs).
|
for @code{dired}, @code{info}, and @code{mailto} URLs).
|
||||||
|
|
||||||
|
If @var{silent} is non-@code{nil}, don't do any messaging while
|
||||||
|
retrieving. If @var{inhibit-cookies} is non-@code{nil}, refuse to
|
||||||
|
store cookies. If @var{timeout} is passed, it should be a number that
|
||||||
|
says (in seconds) how long to wait for a response before giving up.
|
||||||
@end defun
|
@end defun
|
||||||
|
|
||||||
@defun url-retrieve url callback &optional cbargs silent no-cookies
|
@defun url-retrieve url callback &optional cbargs silent no-cookies
|
||||||
|
4
etc/NEWS
4
etc/NEWS
@ -284,6 +284,10 @@ servers.
|
|||||||
programmatically delete all cookies, or cookies from a specific
|
programmatically delete all cookies, or cookies from a specific
|
||||||
domain.
|
domain.
|
||||||
|
|
||||||
|
+++
|
||||||
|
*** `url-retrieve-synchronously' now takes an optional timeout parameter.
|
||||||
|
|
||||||
|
---
|
||||||
*** The URL package now support HTTPS over proxies supporting CONNECT.
|
*** The URL package now support HTTPS over proxies supporting CONNECT.
|
||||||
|
|
||||||
+++
|
+++
|
||||||
|
@ -221,14 +221,20 @@ URL-encoded before it's used."
|
|||||||
buffer))
|
buffer))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun url-retrieve-synchronously (url &optional silent inhibit-cookies)
|
(defun url-retrieve-synchronously (url &optional silent inhibit-cookies timeout)
|
||||||
"Retrieve URL synchronously.
|
"Retrieve URL synchronously.
|
||||||
Return the buffer containing the data, or nil if there are no data
|
Return the buffer containing the data, or nil if there are no data
|
||||||
associated with it (the case for dired, info, or mailto URLs that need
|
associated with it (the case for dired, info, or mailto URLs that need
|
||||||
no further processing). URL is either a string or a parsed URL."
|
no further processing). URL is either a string or a parsed URL.
|
||||||
|
|
||||||
|
If SILENT is non-nil, don't do any messaging while retrieving.
|
||||||
|
If INHIBIT-COOKIES is non-nil, refuse to store cookies. If
|
||||||
|
TIMEOUT is passed, it should be a number that says (in seconds)
|
||||||
|
how long to wait for a response before giving up."
|
||||||
(url-do-setup)
|
(url-do-setup)
|
||||||
|
|
||||||
(let ((retrieval-done nil)
|
(let ((retrieval-done nil)
|
||||||
|
(start-time (current-time))
|
||||||
(asynch-buffer nil))
|
(asynch-buffer nil))
|
||||||
(setq asynch-buffer
|
(setq asynch-buffer
|
||||||
(url-retrieve url (lambda (&rest ignored)
|
(url-retrieve url (lambda (&rest ignored)
|
||||||
@ -250,7 +256,11 @@ no further processing). URL is either a string or a parsed URL."
|
|||||||
;; buffer-local variable so we can find the exact process that we
|
;; buffer-local variable so we can find the exact process that we
|
||||||
;; should be waiting for. In the mean time, we'll just wait for any
|
;; should be waiting for. In the mean time, we'll just wait for any
|
||||||
;; process output.
|
;; process output.
|
||||||
(while (not retrieval-done)
|
(while (and (not retrieval-done)
|
||||||
|
(or (not timeout)
|
||||||
|
(< (float-time (time-subtract
|
||||||
|
(current-time) start-time))
|
||||||
|
timeout)))
|
||||||
(url-debug 'retrieval
|
(url-debug 'retrieval
|
||||||
"Spinning in url-retrieve-synchronously: %S (%S)"
|
"Spinning in url-retrieve-synchronously: %S (%S)"
|
||||||
retrieval-done asynch-buffer)
|
retrieval-done asynch-buffer)
|
||||||
@ -281,7 +291,7 @@ no further processing). URL is either a string or a parsed URL."
|
|||||||
;; `sleep-for' was tried but it lead to other forms of
|
;; `sleep-for' was tried but it lead to other forms of
|
||||||
;; hanging. --Stef
|
;; hanging. --Stef
|
||||||
(unless (or (with-local-quit
|
(unless (or (with-local-quit
|
||||||
(accept-process-output proc))
|
(accept-process-output proc 1))
|
||||||
(null proc))
|
(null proc))
|
||||||
;; accept-process-output returned nil, maybe because the process
|
;; accept-process-output returned nil, maybe because the process
|
||||||
;; exited (and may have been replaced with another). If we got
|
;; exited (and may have been replaced with another). If we got
|
||||||
|
Loading…
Reference in New Issue
Block a user