To try and reduce the number of write syscalls.
This commit is contained in:
parent
deae518b52
commit
7709ffe1d3
1 changed files with 17 additions and 4 deletions
|
@ -63,6 +63,14 @@
|
||||||
(bind sock family addr port)
|
(bind sock family addr port)
|
||||||
sock))
|
sock))
|
||||||
|
|
||||||
|
(define crlf-bv
|
||||||
|
(string->utf8 "\r\n"))
|
||||||
|
|
||||||
|
(define (chunked-output-port-overhead-bytes write-size)
|
||||||
|
(+ (string-length (number->string write-size 16))
|
||||||
|
(bytevector-length crlf-bv)
|
||||||
|
(bytevector-length crlf-bv)))
|
||||||
|
|
||||||
(define* (make-chunked-output-port/knots port #:key (keep-alive? #f)
|
(define* (make-chunked-output-port/knots port #:key (keep-alive? #f)
|
||||||
(buffering 1200))
|
(buffering 1200))
|
||||||
"Returns a new port which translates non-encoded data into a HTTP
|
"Returns a new port which translates non-encoded data into a HTTP
|
||||||
|
@ -74,10 +82,12 @@ 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
|
zero chunk. When the port is closed it will also close PORT, unless
|
||||||
KEEP-ALIVE? is true."
|
KEEP-ALIVE? is true."
|
||||||
(define (write! bv start count)
|
(define (write! bv start count)
|
||||||
(put-string port (number->string count 16))
|
(let ((len-string
|
||||||
(put-string port "\r\n")
|
(number->string count 16)))
|
||||||
|
(put-string port len-string))
|
||||||
|
(put-bytevector port crlf-bv 0 2)
|
||||||
(put-bytevector port bv start count)
|
(put-bytevector port bv start count)
|
||||||
(put-string port "\r\n")
|
(put-bytevector port crlf-bv 0 2)
|
||||||
(force-output port)
|
(force-output port)
|
||||||
count)
|
count)
|
||||||
|
|
||||||
|
@ -401,7 +411,10 @@ on the procedure being called at any particular time."
|
||||||
(make-chunked-output-port/knots
|
(make-chunked-output-port/knots
|
||||||
client
|
client
|
||||||
#:keep-alive? #t
|
#:keep-alive? #t
|
||||||
#:buffering buffer-size))))
|
#:buffering
|
||||||
|
(- buffer-size
|
||||||
|
(chunked-output-port-overhead-bytes
|
||||||
|
buffer-size))))))
|
||||||
(set-port-encoding! body-port charset)
|
(set-port-encoding! body-port charset)
|
||||||
(let ((body-written?
|
(let ((body-written?
|
||||||
(with-exception-handler
|
(with-exception-handler
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue