[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/02: make-chunked-output-port buffering fix
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/02: make-chunked-output-port buffering fix |
Date: |
Mon, 11 Apr 2016 20:28:18 +0000 |
wingo pushed a commit to branch wip-port-refactor
in repository guile.
commit 55fb8f4e7e8181ef09e49ea9d917ca25f9fe8159
Author: Andy Wingo <address@hidden>
Date: Mon Apr 11 22:22:39 2016 +0200
make-chunked-output-port buffering fix
* module/web/http.scm (make-chunked-output-port): Add #:buffering
argument, defaulting to 1200 (some random value under the MTU). This
will force a flush every so often, and not every character as would
otherwise be the case after this port rewrite.
---
module/web/http.scm | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/module/web/http.scm b/module/web/http.scm
index 8a07f6d..9e8e4a3 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1972,13 +1972,15 @@ closed it will also close PORT, unless the KEEP-ALIVE?
is true."
(loop to-read 0))
(make-custom-binary-input-port "chunked input port" read! #f #f close))
-(define* (make-chunked-output-port port #:key (keep-alive? #f))
+(define* (make-chunked-output-port port #:key (keep-alive? #f)
+ (buffering 1200))
"Returns a new port which translates non-encoded data into a HTTP
-chunked transfer encoded data and writes this to PORT. Data
-written to this port is buffered until the port is flushed, at which
-point it is all sent as one chunk. Take care to close the port when
-done, as it will output the remaining data, and encode the final zero
-chunk. When the port is closed it will also close PORT, unless
+chunked transfer encoded data and writes this to PORT. Data written to
+this port is buffered until the port is flushed, at which point it is
+all sent as one chunk. The port will otherwise be flushed every
+BUFFERING bytes, which defaults to 1200. Take care to close the port
+when done, as it will output the remaining data, and encode the final
+zero chunk. When the port is closed it will also close PORT, unless
KEEP-ALIVE? is true."
(define (q-for-each f q)
(while (not (q-empty? q))
@@ -2005,7 +2007,9 @@ KEEP-ALIVE? is true."
(force-output port)
(unless keep-alive?
(close-port port)))
- (make-soft-port (vector put-char put-string flush #f close) "w"))
+ (let ((ret (make-soft-port (vector put-char put-string flush #f close) "w")))
+ (setvbuf ret 'block buffering)
+ ret))
(define %http-proxy-port? (make-object-property))
(define (http-proxy-port? port) (%http-proxy-port? port))