From 8ca97482b01cf1a6aa538cc5a2d1f71fb60f080c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 16 Jan 2014 23:43:31 +0100 Subject: Custom binary input ports support 'setvbuf'. * libguile/r6rs-ports.c (CBIP_BUFFER_SIZE): Adjust comment. Set to 8KiB. (SCM_SET_CBIP_BYTEVECTOR): New macro. (cbip_setvbuf): New function. (make_cbip): Set PORT's 'setvbuf' internal field. (cbip_fill_input): Check whether PORT is buffered. When unbuffered, check whether BV can hold C_REQUESTED bytes, and allocate a new bytevector if not; copy the data back from BV to c_port->read_pos. Remove 'again' label, and don't loop there. * test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports")["custom binary input port unbuffered & 'port-position'", "custom binary input port unbuffered & 'read!' calls", "custom binary input port, unbuffered then buffered", "custom binary input port, buffered then unbuffered"]: New tests. * doc/ref/api-io.texi (R6RS Binary Input): Document the buffering of custom binary input ports, and link to 'setvbuf'. --- doc/ref/api-io.texi | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'doc/ref/api-io.texi') diff --git a/doc/ref/api-io.texi b/doc/ref/api-io.texi index f1170eb2c..02d92a2d7 100644 --- a/doc/ref/api-io.texi +++ b/doc/ref/api-io.texi @@ -1816,6 +1816,10 @@ indicating the position of the next byte is to read. Finally, if @var{close} is not @code{#f}, it must be a thunk. It is invoked when the custom binary input port is closed. +The returned port is fully buffered by default, but its buffering mode +can be changed using @code{setvbuf} (@pxref{Ports and File Descriptors, +@code{setvbuf}}). + Using a custom binary input port, the @code{open-bytevector-input-port} procedure could be implemented as follows: -- cgit v1.2.3