summaryrefslogtreecommitdiff
path: root/guix/progress.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-12-02 22:49:39 +0100
committerLudovic Courtès <ludo@gnu.org>2020-12-08 22:30:08 +0100
commit5ff521452b9ec2aae9ed8e4bb7bdc250a581f203 (patch)
tree550eb2cc894c1c76d565328b75c14d986dcf760e /guix/progress.scm
parent711df9ef3c04a0e0d7e844bed4c6b260ea1f65c1 (diff)
downloadguix-patches-5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.tar
guix-patches-5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.tar.gz
substitute: Cache and reuse connections while substituting.
That way, when fetching a series of substitutes from the same server(s), the connection is reused instead of being closed/opened for each substitutes, which saves on network round trips and TLS handshakes. * guix/http-client.scm (http-fetch): Add #:keep-alive? and honor it. * guix/progress.scm (progress-report-port): Add #:close? parameter and honor it. * guix/scripts/substitute.scm (at-most): Return the tail as a second value. (fetch): Add #:port and #:keep-alive? and honor them. (%max-cached-connections): New variable. (open-connection-for-uri/cached, call-with-cached-connection): New procedures. (with-cached-connection): New macro. (process-substitution): Wrap 'fetch' call in 'with-cached-connection'. Pass #:close? to 'progress-report-port'.
Diffstat (limited to 'guix/progress.scm')
-rw-r--r--guix/progress.scm8
1 files changed, 5 insertions, 3 deletions
diff --git a/guix/progress.scm b/guix/progress.scm
index fec65b424c..cd80ae620a 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -337,9 +337,10 @@ should be a <progress-reporter> object."
(report total)
(loop total (get-bytevector-n! in buffer 0 buffer-size))))))))
-(define (progress-report-port reporter port)
+(define* (progress-report-port reporter port #:key (close? #t))
"Return a port that continuously reports the bytes read from PORT using
-REPORTER, which should be a <progress-reporter> object."
+REPORTER, which should be a <progress-reporter> object. When CLOSE? is true,
+PORT is closed when the returned port is closed."
(match reporter
(($ <progress-reporter> start report stop)
(let* ((total 0)
@@ -364,5 +365,6 @@ REPORTER, which should be a <progress-reporter> object."
;; trace.
(unless (zero? total)
(stop))
- (close-port port)))))))
+ (when close?
+ (close-port port))))))))