guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 01/02: web: 'tls-wrap' avoids intermediate buffer.


From: Ludovic Courtès
Subject: [Guile-commits] 01/02: web: 'tls-wrap' avoids intermediate buffer.
Date: Fri, 19 Mar 2021 09:14:31 -0400 (EDT)

civodul pushed a commit to branch master
in repository guile.

commit e4f54d4b32b0dc4233ed16e24db5cc913fccf088
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Mar 19 14:08:58 2021 +0100

    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'.
---
 module/web/client.scm | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/module/web/client.scm b/module/web/client.scm
index 540dcdd..76d9cc4 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]