summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2021-03-19 14:08:58 +0100
committerLudovic Courtès <ludo@gnu.org>2021-03-19 14:08:58 +0100
commite4f54d4b32b0dc4233ed16e24db5cc913fccf088 (patch)
tree1543eeb09a2f8a664ea7614fe9697a3ead50f9f8
parentef7952984cdf640ee1d4f2445675a142ccee2cf9 (diff)
downloadguile-e4f54d4b32b0dc4233ed16e24db5cc913fccf088.tar.gz
web: 'tls-wrap' avoids intermediate buffer.
This mirrors Guix commit 279d932b1ca7bfbb8657c41a84616dd0dfc6e0a8. * module/web/client.scm (tls-wrap)[read!]: Read straight into BV instead of calling 'get-bytevector-some' and 'unget-bytevector'.
-rw-r--r--module/web/client.scm17
1 files changed, 7 insertions, 10 deletions
diff --git a/module/web/client.scm b/module/web/client.scm
index 540dcdd44..76d9cc45a 100644
--- a/module/web/client.scm
+++ b/module/web/client.scm
@@ -1,6 +1,6 @@
;;; Web client
-;; Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 Free Software Foundation, Inc.
+;; Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021 Free Software Foundation, Inc.
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
@@ -244,10 +244,10 @@ host name without trailing dot."
;; underlying socket.
(let ((record (session-record-port session)))
(define (read! bv start count)
- (define read-bv
+ (define read
(catch 'gnutls-error
(lambda ()
- (get-bytevector-some record))
+ (get-bytevector-n! record bv start count))
(lambda (key err proc . rest)
;; When responding to "Connection: close" requests, some
;; servers close the connection abruptly after sending the
@@ -256,13 +256,10 @@ host name without trailing dot."
(if (eq? err error/premature-termination)
the-eof-object
(apply throw key err proc rest)))))
- (if (eof-object? read-bv)
- 0 ; read! returns 0 on eof-object
- (let ((read-bv-len (bytevector-length read-bv)))
- (bytevector-copy! read-bv 0 bv start (min read-bv-len count))
- (when (< count read-bv-len)
- (unget-bytevector record bv count (- read-bv-len count)))
- read-bv-len)))
+
+ (if (eof-object? read)
+ 0
+ read))
(define (write! bv start count)
(put-bytevector record bv start count)
(force-output record)