summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-04-11 22:22:39 +0200
committerAndy Wingo <wingo@pobox.com>2016-04-11 22:23:47 +0200
commit55fb8f4e7e8181ef09e49ea9d917ca25f9fe8159 (patch)
tree64d080a99fbde06ba3609d68fbe73462093e7ec0
parent3ce52fa5034acd59eadc2d818cb813a336fb5b29 (diff)
downloadguile-55fb8f4e7e8181ef09e49ea9d917ca25f9fe8159.tar.gz
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.
-rw-r--r--module/web/http.scm18
1 files changed, 11 insertions, 7 deletions
diff --git a/module/web/http.scm b/module/web/http.scm
index 8a07f6d0d..9e8e4a3a5 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))