Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports

From: Andy Wingo <[email-masked]>
Date: Fri, 12 Jan 2018 11:33:32 +0100

On Fri 12 Jan 2018 11:15, [email-masked] (Ludovic Courtès) writes:

> Andy Wingo <[email-masked]> skribis:
>
>> On Thu 11 Jan 2018 22:55, Mark H Weaver <[email-masked]> writes:
>
> [...]
>
>>>>> Out of curiosity, is there a reason why you're using an unbuffered port
>>>>> in your use case?
>>>>
>>>> It’s to implement redirect à la socat:
>>>>
>>>>   https://git.savannah.gnu.org/cgit/guix.git/commit/?id=17af5d51de7c40756a4a39d336f81681de2ba447
>>>
>>> Why is an unbuffered port being used here?  Can we change it to a
>>> buffered port?
>>
>> This was also a question I had!  If you make it a buffered port at 4096
>> bytes (for example), then get-bytevector-some works exactly like you
>> want it to, no?
>
> It might work, but that’s more by chance no?

No, it is reliable.  get-bytevector-some on a buffered port must either
return all the buffered bytes or perform exactly one read (up to the
buffer size) and either return those bytes or EOF.  As far as I
understand, that is exactly what you want.

Using buffered ports has two additional advantages: you get to specify
the read size, and returned bytevectors can be allocated to precisely
the right size (no need to overallocate then truncate).

Andy