summaryrefslogtreecommitdiff
path: root/lisp/url
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen <larsi@gnus.org>2016-04-26 00:47:51 +0200
committerLars Magne Ingebrigtsen <larsi@gnus.org>2016-04-26 00:47:51 +0200
commit77ba0f1c5a259615ec049e21d061c4646e29f1d6 (patch)
tree6c0969829ee3200a04ba088c455ceade27b9ff86 /lisp/url
parent4f25bef332264df2e4d096e529a63655fa03c5bc (diff)
downloademacs-77ba0f1c5a259615ec049e21d061c4646e29f1d6.tar.gz
`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).
Diffstat (limited to 'lisp/url')
-rw-r--r--lisp/url/url.el18
1 files changed, 14 insertions, 4 deletions
diff --git a/lisp/url/url.el b/lisp/url/url.el
index 4837ba07f7e..6d710e02d63 100644
--- a/lisp/url/url.el
+++ b/lisp/url/url.el
@@ -221,14 +221,20 @@ URL-encoded before it's used."
buffer))
;;;###autoload
-(defun url-retrieve-synchronously (url &optional silent inhibit-cookies)
+(defun url-retrieve-synchronously (url &optional silent inhibit-cookies timeout)
"Retrieve URL synchronously.
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
-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)
(let ((retrieval-done nil)
+ (start-time (current-time))
(asynch-buffer nil))
(setq asynch-buffer
(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
;; should be waiting for. In the mean time, we'll just wait for any
;; 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
"Spinning in url-retrieve-synchronously: %S (%S)"
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
;; hanging. --Stef
(unless (or (with-local-quit
- (accept-process-output proc))
+ (accept-process-output proc 1))
(null proc))
;; accept-process-output returned nil, maybe because the process
;; exited (and may have been replaced with another). If we got