GNU bug report logs - #30066
'get-bytevector-some' returns only 1 byte from unbuffered ports

Previous Next

Package: guile;

Reported by: ludo <at> gnu.org (Ludovic Courtès)

Date: Wed, 10 Jan 2018 15:03:02 UTC

Severity: normal

Tags: notabug

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: ludo <at> gnu.org (Ludovic Courtès)
To: Mark H Weaver <mhw <at> netris.org>
Cc: Andy Wingo <wingo <at> igalia.com>, 30066 <at> debbugs.gnu.org
Subject: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports
Date: Thu, 11 Jan 2018 22:02:29 +0100
Hello,

Mark H Weaver <mhw <at> netris.org> skribis:

> ludo <at> gnu.org (Ludovic Courtès) writes:

[...]

>> +  if (SCM_UNBUFFEREDP (port) && (avail < max_buffer_size))
>> +    {
>> +      /* PORT is unbuffered.  Read as much as possible from PORT.  */
>> +      size_t read;
>> +
>> +      bv = scm_c_make_bytevector (max_buffer_size);
>> +      scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv),
>> +                            avail, cur, avail);
>> +
>> +      read = scm_i_read_bytes (port, bv, avail,
>> +                               SCM_BYTEVECTOR_LENGTH (bv) - avail);
>
> Here's the R6RS specification for 'get-bytevector-some':
>
>   "Reads from BINARY-INPUT-PORT, blocking as necessary, until bytes are
>    available from BINARY-INPUT-PORT or until an end of file is reached.
>    If bytes become available, 'get-bytevector-some' returns a freshly
>    allocated bytevector containing the initial available bytes (at least
>    one), and it updates BINARY-INPUT-PORT to point just past these
>    bytes.  If no input bytes are seen before an end of file is reached,
>    the end-of-file object is returned."
>
> By my reading of this, we should block only if necessary to ensure that
> we return at least one byte (or EOF).  In other words, if we can return
> at least one byte (or EOF), then we must not block, which means that we
> must not initiate another 'read'.

Indeed.  So perhaps the condition above should be changed to:

  if (SCM_UNBUFFEREDP (port) && (avail == 0))

?

> 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

Thanks,
Ludo’.




This bug report was last modified 7 years and 99 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.