2016-02-08 06:13:01 +00:00
|
|
|
;;; url-queue.el --- Fetching web pages in parallel -*- lexical-binding: t -*-
|
2011-05-02 17:06:56 +00:00
|
|
|
|
2023-01-01 10:31:12 +00:00
|
|
|
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
|
2011-05-02 17:06:56 +00:00
|
|
|
|
|
|
|
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
|
|
|
|
;; Keywords: comm
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2011-05-02 17:06:56 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; The point of this package is to allow fetching web pages in
|
|
|
|
;; parallel -- but control the level of parallelism to avoid DoS-ing
|
|
|
|
;; web servers and Emacs.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(eval-when-compile (require 'cl-lib))
|
2011-05-02 17:06:56 +00:00
|
|
|
(require 'browse-url)
|
2012-02-06 01:13:24 +00:00
|
|
|
(require 'url-parse)
|
2022-02-20 21:36:46 +00:00
|
|
|
(require 'url-file)
|
2011-05-02 17:06:56 +00:00
|
|
|
|
2011-05-31 20:58:01 +00:00
|
|
|
(defcustom url-queue-parallel-processes 6
|
2011-05-02 17:06:56 +00:00
|
|
|
"The number of concurrent processes."
|
2011-06-01 17:34:24 +00:00
|
|
|
:version "24.1"
|
Make some defcustom types more restrictive
* lisp/abbrev.el (abbrev-suggest-hint-threshold):
* lisp/bookmark.el (bookmark-bmenu-file-column)
(bookmark-menu-length):
* lisp/buff-menu.el (Buffer-menu-size-width)
(Buffer-menu-mode-width):
* lisp/calendar/calendar.el (calendar-week-start-day)
(calendar-intermonth-spacing, calendar-column-width)
(calendar-day-digit-width):
* lisp/calc/calc.el (calc-undo-length):
* lisp/calendar/timeclock.el (timeclock-workday):
* lisp/comint.el (comint-buffer-maximum-size)
(comint-input-ring-size):
* lisp/doc-view.el (doc-view-resolution, doc-view-image-width):
* lisp/emacs-lisp/bytecomp.el (byte-compile-docstring-max-column):
* lisp/emacs-lisp/comp.el (native-comp-debug)
(native-comp-verbose, native-comp-async-jobs-number):
* lisp/emacs-lisp/package.el (package-name-column-width)
(package-version-column-width, package-status-column-width)
(package-archive-column-width):
* lisp/eshell/esh-mode.el (eshell-buffer-maximum-lines):
* lisp/frame.el (blink-cursor-blinks):
* lisp/info.el (Info-breadcrumbs-depth):
* lisp/jit-lock.el (jit-lock-chunk-size):
* lisp/kmacro.el (kmacro-ring-max):
* lisp/menu-bar.el (yank-menu-length, yank-menu-max-items):
* lisp/midnight.el (clean-buffer-list-delay-general)
(clean-buffer-list-delay-special):
* lisp/net/dictionary.el (dictionary-port)
(dictionary-proxy-port):
* lisp/net/ldap.el (ldap-default-port):
* lisp/net/pop3.el (pop3-port, pop3-stream-length):
* lisp/net/rcirc.el (rcirc-default-port):
* lisp/net/sieve-manage.el (sieve-manage-default-port):
* lisp/play/spook.el (spook-phrase-default-count):
* lisp/play/tetris.el (tetris-buffer-width)
(tetris-buffer-height, tetris-width, tetris-height)
(tetris-top-left-x, tetris-top-left-y):
* lisp/profiler.el (profiler-sampling-interval):
* lisp/progmodes/sql.el (sql-port):
* lisp/recentf.el (recentf-max-menu-items):
* lisp/strokes.el (strokes-grid-resolution):
* lisp/tab-bar.el (tab-bar-tab-name-truncated-max):
* lisp/term/xterm.el (xterm-max-cut-length):
* lisp/time.el (display-time-interval, world-clock-timer-second):
* lisp/url/url-cache.el (url-cache-expire-time):
* lisp/url/url-cookie.el (url-cookie-save-interval):
* lisp/url/url-history.el (url-history-save-interval):
* lisp/url/url-queue.el (url-queue-parallel-processes)
(url-queue-timeout):
* lisp/url/url-vars.el (url-max-password-attempts)
(url-max-redirections):
* lisp/vc/emerge.el (emerge-min-visible-lines):
* lisp/vc/vc.el (vc-log-show-limit):
* lisp/window.el (window-min-height, window-min-width):
* lisp/winner.el (winner-ring-size): Use :type natnum.
* lisp/savehist.el (savehist-file-modes): Fix setting to nil value and
use :type natnum.
2022-07-05 14:26:45 +00:00
|
|
|
:type 'natnum
|
2011-05-02 17:06:56 +00:00
|
|
|
:group 'url)
|
|
|
|
|
|
|
|
(defcustom url-queue-timeout 5
|
|
|
|
"How long to let a job live once it's started (in seconds)."
|
2011-06-01 17:34:24 +00:00
|
|
|
:version "24.1"
|
Make some defcustom types more restrictive
* lisp/abbrev.el (abbrev-suggest-hint-threshold):
* lisp/bookmark.el (bookmark-bmenu-file-column)
(bookmark-menu-length):
* lisp/buff-menu.el (Buffer-menu-size-width)
(Buffer-menu-mode-width):
* lisp/calendar/calendar.el (calendar-week-start-day)
(calendar-intermonth-spacing, calendar-column-width)
(calendar-day-digit-width):
* lisp/calc/calc.el (calc-undo-length):
* lisp/calendar/timeclock.el (timeclock-workday):
* lisp/comint.el (comint-buffer-maximum-size)
(comint-input-ring-size):
* lisp/doc-view.el (doc-view-resolution, doc-view-image-width):
* lisp/emacs-lisp/bytecomp.el (byte-compile-docstring-max-column):
* lisp/emacs-lisp/comp.el (native-comp-debug)
(native-comp-verbose, native-comp-async-jobs-number):
* lisp/emacs-lisp/package.el (package-name-column-width)
(package-version-column-width, package-status-column-width)
(package-archive-column-width):
* lisp/eshell/esh-mode.el (eshell-buffer-maximum-lines):
* lisp/frame.el (blink-cursor-blinks):
* lisp/info.el (Info-breadcrumbs-depth):
* lisp/jit-lock.el (jit-lock-chunk-size):
* lisp/kmacro.el (kmacro-ring-max):
* lisp/menu-bar.el (yank-menu-length, yank-menu-max-items):
* lisp/midnight.el (clean-buffer-list-delay-general)
(clean-buffer-list-delay-special):
* lisp/net/dictionary.el (dictionary-port)
(dictionary-proxy-port):
* lisp/net/ldap.el (ldap-default-port):
* lisp/net/pop3.el (pop3-port, pop3-stream-length):
* lisp/net/rcirc.el (rcirc-default-port):
* lisp/net/sieve-manage.el (sieve-manage-default-port):
* lisp/play/spook.el (spook-phrase-default-count):
* lisp/play/tetris.el (tetris-buffer-width)
(tetris-buffer-height, tetris-width, tetris-height)
(tetris-top-left-x, tetris-top-left-y):
* lisp/profiler.el (profiler-sampling-interval):
* lisp/progmodes/sql.el (sql-port):
* lisp/recentf.el (recentf-max-menu-items):
* lisp/strokes.el (strokes-grid-resolution):
* lisp/tab-bar.el (tab-bar-tab-name-truncated-max):
* lisp/term/xterm.el (xterm-max-cut-length):
* lisp/time.el (display-time-interval, world-clock-timer-second):
* lisp/url/url-cache.el (url-cache-expire-time):
* lisp/url/url-cookie.el (url-cookie-save-interval):
* lisp/url/url-history.el (url-history-save-interval):
* lisp/url/url-queue.el (url-queue-parallel-processes)
(url-queue-timeout):
* lisp/url/url-vars.el (url-max-password-attempts)
(url-max-redirections):
* lisp/vc/emerge.el (emerge-min-visible-lines):
* lisp/vc/vc.el (vc-log-show-limit):
* lisp/window.el (window-min-height, window-min-width):
* lisp/winner.el (winner-ring-size): Use :type natnum.
* lisp/savehist.el (savehist-file-modes): Fix setting to nil value and
use :type natnum.
2022-07-05 14:26:45 +00:00
|
|
|
:type 'natnum
|
2011-05-02 17:06:56 +00:00
|
|
|
:group 'url)
|
|
|
|
|
|
|
|
;;; Internal variables.
|
|
|
|
|
|
|
|
(defvar url-queue nil)
|
2016-02-08 06:13:01 +00:00
|
|
|
(defvar url-queue-progress-timer nil)
|
2011-05-02 17:06:56 +00:00
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(cl-defstruct url-queue
|
2011-05-02 17:06:56 +00:00
|
|
|
url callback cbargs silentp
|
2012-02-08 00:04:42 +00:00
|
|
|
buffer start-time pre-triggered
|
2018-04-13 13:08:18 +00:00
|
|
|
inhibit-cookiesp context-buffer)
|
2011-05-02 17:06:56 +00:00
|
|
|
|
2011-05-02 18:15:39 +00:00
|
|
|
;;;###autoload
|
2012-02-08 00:04:42 +00:00
|
|
|
(defun url-queue-retrieve (url callback &optional cbargs silent inhibit-cookies)
|
2011-05-02 17:06:56 +00:00
|
|
|
"Retrieve URL asynchronously and call CALLBACK with CBARGS when finished.
|
2012-02-10 03:23:47 +00:00
|
|
|
This is like `url-retrieve' (which see for details of the arguments),
|
2012-02-10 17:22:09 +00:00
|
|
|
but with limits on the degree of parallelism. The variable
|
|
|
|
`url-queue-parallel-processes' sets the number of concurrent processes.
|
|
|
|
The variable `url-queue-timeout' sets a timeout."
|
2011-05-02 17:06:56 +00:00
|
|
|
(setq url-queue
|
|
|
|
(append url-queue
|
|
|
|
(list (make-url-queue :url url
|
|
|
|
:callback callback
|
|
|
|
:cbargs cbargs
|
2012-02-08 00:04:42 +00:00
|
|
|
:silentp silent
|
2018-04-13 13:08:18 +00:00
|
|
|
:inhibit-cookiesp inhibit-cookies
|
|
|
|
:context-buffer (current-buffer)))))
|
2012-02-06 01:13:24 +00:00
|
|
|
(url-queue-setup-runners))
|
|
|
|
|
2014-01-05 02:56:08 +00:00
|
|
|
;; To ensure asynch behavior, we start the required number of queue
|
2012-02-06 01:13:24 +00:00
|
|
|
;; runners from `run-with-idle-timer'. So we're basically going
|
|
|
|
;; through the queue in two ways: 1) synchronously when a program
|
|
|
|
;; calls `url-queue-retrieve' (which will then start the required
|
|
|
|
;; number of queue runners), and 2) at the exit of each job, which
|
|
|
|
;; will then not start any further threads, but just reuse the
|
|
|
|
;; previous "slot".
|
|
|
|
|
|
|
|
(defun url-queue-setup-runners ()
|
|
|
|
(let ((running 0)
|
|
|
|
waiting)
|
|
|
|
(dolist (entry url-queue)
|
|
|
|
(cond
|
|
|
|
((or (url-queue-start-time entry)
|
|
|
|
(url-queue-pre-triggered entry))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(cl-incf running))
|
2012-02-06 01:13:24 +00:00
|
|
|
((not waiting)
|
|
|
|
(setq waiting entry))))
|
|
|
|
(when (and waiting
|
|
|
|
(< running url-queue-parallel-processes))
|
|
|
|
(setf (url-queue-pre-triggered waiting) t)
|
2016-02-08 06:13:01 +00:00
|
|
|
;; We start fetching from this idle timer...
|
|
|
|
(run-with-idle-timer 0.01 nil #'url-queue-run-queue)
|
|
|
|
;; And then we set up a separate timer to ensure progress when a
|
|
|
|
;; web server is unresponsive.
|
|
|
|
(unless url-queue-progress-timer
|
|
|
|
(setq url-queue-progress-timer
|
|
|
|
(run-with-idle-timer 1 1 #'url-queue-check-progress))))))
|
2011-05-02 17:06:56 +00:00
|
|
|
|
|
|
|
(defun url-queue-run-queue ()
|
|
|
|
(url-queue-prune-old-entries)
|
|
|
|
(let ((running 0)
|
|
|
|
waiting)
|
|
|
|
(dolist (entry url-queue)
|
2011-05-02 17:28:34 +00:00
|
|
|
(cond
|
|
|
|
((url-queue-start-time entry)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(cl-incf running))
|
2011-05-02 17:28:34 +00:00
|
|
|
((not waiting)
|
|
|
|
(setq waiting entry))))
|
2011-05-02 17:06:56 +00:00
|
|
|
(when (and waiting
|
|
|
|
(< running url-queue-parallel-processes))
|
|
|
|
(setf (url-queue-start-time waiting) (float-time))
|
|
|
|
(url-queue-start-retrieve waiting))))
|
|
|
|
|
2016-02-08 06:13:01 +00:00
|
|
|
(defun url-queue-check-progress ()
|
|
|
|
(when url-queue-progress-timer
|
|
|
|
(if url-queue
|
|
|
|
(url-queue-run-queue)
|
|
|
|
(cancel-timer url-queue-progress-timer)
|
|
|
|
(setq url-queue-progress-timer nil))))
|
|
|
|
|
2011-05-02 17:06:56 +00:00
|
|
|
(defun url-queue-callback-function (status job)
|
2020-07-18 17:59:19 +00:00
|
|
|
(let ((buffer (current-buffer)))
|
|
|
|
(setq url-queue (delq job url-queue))
|
|
|
|
(when (and (eq (car status) :error)
|
|
|
|
(eq (cadr (cadr status)) 'connection-failed))
|
|
|
|
;; If we get a connection error, then flush all other jobs from
|
|
|
|
;; the host from the queue. This particularly makes sense if the
|
|
|
|
;; error really is a DNS resolver issue, which happens
|
|
|
|
;; synchronously and totally halts Emacs.
|
|
|
|
(url-queue-remove-jobs-from-host
|
|
|
|
(plist-get (nthcdr 3 (cadr status)) :host)))
|
|
|
|
(url-queue-run-queue)
|
|
|
|
;; Somehow something deep in the bowels in the URL library may
|
|
|
|
;; have killed off the current buffer. So check that it's still
|
|
|
|
;; alive before doing anything, and if not, just create a dummy
|
|
|
|
;; buffer and do the callback anyway.
|
|
|
|
(unless (buffer-live-p buffer)
|
|
|
|
(set-buffer (generate-new-buffer " *temp*")))
|
|
|
|
(apply (url-queue-callback job) (cons status (url-queue-cbargs job)))))
|
2011-05-02 17:06:56 +00:00
|
|
|
|
2012-02-06 01:13:24 +00:00
|
|
|
(defun url-queue-remove-jobs-from-host (host)
|
|
|
|
(let ((jobs nil))
|
|
|
|
(dolist (job url-queue)
|
|
|
|
(when (equal (url-host (url-generic-parse-url (url-queue-url job)))
|
|
|
|
host)
|
|
|
|
(push job jobs)))
|
|
|
|
(dolist (job jobs)
|
2012-02-14 18:43:21 +00:00
|
|
|
(url-queue-kill-job job)
|
2012-02-06 01:13:24 +00:00
|
|
|
(setq url-queue (delq job url-queue)))))
|
2012-02-10 03:23:47 +00:00
|
|
|
|
2011-05-02 17:06:56 +00:00
|
|
|
(defun url-queue-start-retrieve (job)
|
2011-05-02 18:15:39 +00:00
|
|
|
(setf (url-queue-buffer job)
|
2011-05-02 17:06:56 +00:00
|
|
|
(ignore-errors
|
2022-01-21 14:22:24 +00:00
|
|
|
(with-current-buffer (if (buffer-live-p
|
|
|
|
(url-queue-context-buffer job))
|
2018-04-13 13:08:18 +00:00
|
|
|
(url-queue-context-buffer job)
|
|
|
|
(current-buffer))
|
2022-01-21 14:22:24 +00:00
|
|
|
(let ((url-request-noninteractive t)
|
2022-03-06 16:41:18 +00:00
|
|
|
(url-allow-non-local-files t))
|
2022-01-21 14:22:24 +00:00
|
|
|
(url-retrieve (url-queue-url job)
|
|
|
|
#'url-queue-callback-function (list job)
|
|
|
|
(url-queue-silentp job)
|
|
|
|
(url-queue-inhibit-cookiesp job)))))))
|
2011-05-02 17:06:56 +00:00
|
|
|
|
|
|
|
(defun url-queue-prune-old-entries ()
|
|
|
|
(let (dead-jobs)
|
|
|
|
(dolist (job url-queue)
|
2011-05-02 18:30:48 +00:00
|
|
|
;; Kill jobs that have lasted longer than the timeout.
|
2011-05-02 17:06:56 +00:00
|
|
|
(when (and (url-queue-start-time job)
|
Avoid some double-rounding of Lisp timestamps
Also, simplify some time-related Lisp timestamp code
while we’re in the neighborhood.
* lisp/battery.el (battery-linux-proc-acpi)
(battery-linux-sysfs, battery-upower, battery-bsd-apm):
* lisp/calendar/timeclock.el (timeclock-seconds-to-string)
(timeclock-log, timeclock-last-period)
(timeclock-entry-length, timeclock-entry-list-span)
(timeclock-find-discrep, timeclock-generate-report):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/completion.el (cmpl-hours-since-origin):
* lisp/ecomplete.el (ecomplete-decay-1):
* lisp/emacs-lisp/ert.el (ert--results-update-stats-display)
(ert--results-update-stats-display-maybe):
* lisp/emacs-lisp/timer-list.el (list-timers):
* lisp/emacs-lisp/timer.el (timer-until)
(timer-event-handler):
* lisp/erc/erc-backend.el (erc-server-send-ping)
(erc-server-send-queue, erc-handle-parsed-server-response)
(erc-handle-unknown-server-response):
* lisp/erc/erc-track.el (erc-buffer-visible):
* lisp/erc/erc.el (erc-lurker-cleanup, erc-lurker-p)
(erc-cmd-PING, erc-send-current-line):
* lisp/eshell/em-pred.el (eshell-pred-file-time):
* lisp/eshell/em-unix.el (eshell-show-elapsed-time):
* lisp/gnus/gnus-icalendar.el (gnus-icalendar-event:org-timestamp):
* lisp/gnus/gnus-int.el (gnus-backend-trace):
* lisp/gnus/gnus-sum.el (gnus-user-date):
* lisp/gnus/mail-source.el (mail-source-delete-crash-box):
* lisp/gnus/nnmaildir.el (nnmaildir--scan):
* lisp/ibuf-ext.el (ibuffer-mark-old-buffers):
* lisp/gnus/nnmaildir.el (nnmaildir--scan):
* lisp/mouse.el (mouse--down-1-maybe-follows-link)
(mouse--click-1-maybe-follows-link):
* lisp/mpc.el (mpc--faster-toggle):
* lisp/net/rcirc.el (rcirc-handler-ctcp-KEEPALIVE)
(rcirc-sentinel):
* lisp/net/tramp-cache.el (tramp-get-file-property):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-newer-than-file-p)
(tramp-maybe-open-connection):
* lisp/net/tramp-smb.el (tramp-smb-maybe-open-connection):
* lisp/org/org-clock.el (org-clock-resolve):
(org-resolve-clocks, org-clock-in, org-clock-out, org-clock-sum):
* lisp/org/org-timer.el (org-timer-start)
(org-timer-pause-or-continue, org-timer-seconds):
* lisp/org/org.el (org-evaluate-time-range):
* lisp/org/ox-publish.el (org-publish-cache-ctime-of-src):
* lisp/pixel-scroll.el (pixel-scroll-in-rush-p):
* lisp/play/hanoi.el (hanoi-move-ring):
* lisp/proced.el (proced-format-time):
* lisp/progmodes/cpp.el (cpp-progress-message):
* lisp/progmodes/flymake.el (flymake--handle-report):
* lisp/progmodes/js.el (js--wait-for-matching-output):
* lisp/subr.el (progress-reporter-do-update):
* lisp/term/xterm.el (xterm--read-event-for-query):
* lisp/time.el (display-time-update, emacs-uptime):
* lisp/tooltip.el (tooltip-delay):
* lisp/url/url-cookie.el (url-cookie-parse-file-netscape):
* lisp/url/url-queue.el (url-queue-prune-old-entries):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/xt-mouse.el (xterm-mouse-event):
Avoid double-rounding of time-related values. Simplify.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
When hoping for the best (unlikely), use a better decoded time.
(icalendar--convert-sexp-to-ical): Avoid unnecessary encode-time.
* lisp/calendar/timeclock.el (timeclock-when-to-leave):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/desktop.el (desktop-create-buffer):
* lisp/emacs-lisp/benchmark.el (benchmark-elapse):
* lisp/gnus/gnus-art.el (article-lapsed-string):
* lisp/gnus/gnus-group.el (gnus-group-timestamp-delta):
* lisp/gnus/nnmail.el (nnmail-expired-article-p):
* lisp/gnus/nnmaildir.el (nnmaildir-request-expire-articles):
* lisp/nxml/rng-maint.el (rng-time-function):
* lisp/org/org-clock.el (org-clock-get-clocked-time)
(org-clock-resolve, org-resolve-clocks, org-resolve-clocks-if-idle):
* lisp/org/org-habit.el (org-habit-insert-consistency-graphs):
* lisp/progmodes/vhdl-mode.el (vhdl-update-progress-info)
(vhdl-fix-case-region-1):
Use time-since instead of open-coding most of it.
* lisp/erc/erc-dcc.el (erc-dcc-get-sentinel):
* lisp/erc/erc.el (erc-string-to-emacs-time, erc-time-gt):
Now obsolete. All uses changed.
(erc-time-diff): Accept all Lisp time values.
All uses changed.
* lisp/gnus/gnus-demon.el (gnus-demon-idle-since):
* lisp/gnus/gnus-score.el (gnus-score-headers):
* lisp/gnus/nneething.el (nneething-make-head):
* lisp/gnus/nnheader.el (nnheader-message-maybe):
* lisp/gnus/nnimap.el (nnimap-keepalive):
* lisp/image.el (image-animate-timeout):
* lisp/mail/feedmail.el (feedmail-rfc822-date):
* lisp/net/imap.el (imap-wait-for-tag):
* lisp/net/newst-backend.el (newsticker--image-get):
* lisp/net/rcirc.el (rcirc-handler-317, rcirc-handler-333):
* lisp/obsolete/xesam.el (xesam-refresh-entry):
* lisp/org/org-agenda.el (org-agenda-show-clocking-issues)
(org-agenda-check-clock-gap, org-agenda-to-appt):
* lisp/org/org-capture.el (org-capture-set-target-location):
* lisp/org/org-clock.el (org-clock-resolve-clock)
(org-clocktable-steps):
* lisp/org/org-colview.el (org-columns-edit-value)
(org-columns, org-agenda-columns):
* lisp/org/org-duration.el (org-duration-from-minutes):
* lisp/org/org-element.el (org-element-cache-sync-duration)
(org-element-cache-sync-break)
(org-element--cache-interrupt-p, org-element--cache-sync):
* lisp/org/org-habit.el (org-habit-get-faces)
* lisp/org/org-indent.el (org-indent-add-properties):
* lisp/org/org-table.el (org-table-sum):
* lisp/org/org-timer.el (org-timer-show-remaining-time)
(org-timer-set-timer):
* lisp/org/org.el (org-babel-load-file, org-today)
(org-auto-repeat-maybe, org-2ft, org-time-stamp)
(org-read-date-analyze, org-time-stamp-to-now)
(org-small-year-to-year, org-goto-calendar):
* lisp/org/ox.el (org-export-insert-default-template):
* lisp/ses.el (ses--time-check):
* lisp/type-break.el (type-break-time-warning)
(type-break-statistics, type-break-demo-boring):
* lisp/url/url-cache.el (url-cache-expired)
(url-cache-prune-cache):
* lisp/vc/vc-git.el (vc-git-stash-snapshot):
* lisp/erc/erc-match.el (erc-log-matches-come-back):
Simplify.
2019-02-23 02:32:31 +00:00
|
|
|
(time-less-p url-queue-timeout
|
|
|
|
(time-since (url-queue-start-time job))))
|
2011-05-02 17:06:56 +00:00
|
|
|
(push job dead-jobs)))
|
|
|
|
(dolist (job dead-jobs)
|
2012-02-14 18:43:21 +00:00
|
|
|
(url-queue-kill-job job)
|
2011-05-02 18:15:39 +00:00
|
|
|
(setq url-queue (delq job url-queue)))))
|
2011-05-02 17:06:56 +00:00
|
|
|
|
2012-02-14 18:43:21 +00:00
|
|
|
(defun url-queue-kill-job (job)
|
|
|
|
(when (bufferp (url-queue-buffer job))
|
2012-02-20 12:12:48 +00:00
|
|
|
(let (process)
|
|
|
|
(while (setq process (get-buffer-process (url-queue-buffer job)))
|
|
|
|
(set-process-sentinel process 'ignore)
|
|
|
|
(ignore-errors
|
2012-03-14 02:44:09 +00:00
|
|
|
(delete-process process)))))
|
|
|
|
;; Call the callback with an error message to ensure that the caller
|
|
|
|
;; is notified that the job has failed.
|
|
|
|
(with-current-buffer
|
2012-03-25 13:38:22 +00:00
|
|
|
(if (and (bufferp (url-queue-buffer job))
|
|
|
|
(buffer-live-p (url-queue-buffer job)))
|
2017-10-28 00:09:17 +00:00
|
|
|
;; Use the (partially filled) process buffer if it exists.
|
2012-03-14 02:44:09 +00:00
|
|
|
(url-queue-buffer job)
|
|
|
|
;; If not, just create a new buffer, which will probably be
|
|
|
|
;; killed again by the caller.
|
|
|
|
(generate-new-buffer " *temp*"))
|
|
|
|
(apply (url-queue-callback job)
|
|
|
|
(cons (list :error (list 'error 'url-queue-timeout
|
|
|
|
"Queue timeout exceeded"))
|
|
|
|
(url-queue-cbargs job)))))
|
2012-02-14 18:43:21 +00:00
|
|
|
|
2011-05-02 17:06:56 +00:00
|
|
|
(provide 'url-queue)
|
|
|
|
|
|
|
|
;;; url-queue.el ends here
|