unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: guile-devel@gnu.org
Subject: Re: Reading data from a file descriptor
Date: Mon, 16 Nov 2015 14:02:49 +0100	[thread overview]
Message-ID: <20151116130249.GA4154@tuxteam.de> (raw)
In-Reply-To: <87h9kpvqw1.fsf@netris.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Nov 13, 2015 at 10:51:58AM -0500, Mark H Weaver wrote:
> Jan Synáček <jan.synacek@gmail.com> writes:
> 
> > On Sun, Nov 8, 2015 at 12:49 AM, Andreas Rottmann <a.rottmann@gmx.at>
> > wrote:
> >
> >     Also note that if there's no requirement to actually implement
> >     this in
> >     C, there's `fdes->inport' and `fdes->outport' on the Scheme level,
> >     so
> >     something like the following would be analogous to the C example
> >     code
> >     posted:
> >     
> >     (import (ice-9 binary-ports))
> >     
> >     (define (process-fd fd)
> >     (let ((port (fdes->inport fd)))
> >     (display "read: ")
> >     (display (get-bytevector-n port 100))
> >     (display "\n")))
> >     
> >     (process-fd (acquire-valid-fd))
> >     
> >
> > This is something very similar that I ended up with. Just instead of
> > get-byte-vector, I used read-string!/partial.
> 
> I would advise against using 'read-string!/partial' or any of the
> procedures in (ice-9 rw).  This is a vestigial module from Guile 1.8
> when strings were arrays of bytes, which they no longer are.  We should
> probably mark them as deprecated.
> 
> For one thing, when we switch to using UTF-8 as the internal string
> encoding, it will not be possible to keep 'read-string!/partial'
> efficient.  It will necessarily have to do an encoding conversion.
> 
> In Guile 2+, I would advise using byte vectors when working with binary
> data.  Portions of these can be converted to strings with a given
> encoding if desired.  I might be able to give better advice if I knew
> more about what you are doing here.

Mark,

what Jan is after (and what I'd like to have too) is something
akin to Unix read(2) with O_NONBLOCK: provide a buffer, request
(up to) N bytes from the file (descriptor) and get an answer
(with possibly less bytes).

I tried that a while ago and was surprised that I had to resort
to (character) strings, with all the downsides you mention. Something
like that for byte vectors would be awesome. Either it exists (and
neither Jan nor me have succeeded in finding it) or it doesn't.

I'll go have a look later to see whether my recollection is accurate.

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlZJ0/kACgkQBcgs9XrR2kb93QCdF1K/IT/Ma+CkOFAqQgul9px/
tDMAnRoki8ODfD3tqwZSyL1GArAfDnpn
=AuBJ
-----END PGP SIGNATURE-----



  parent reply	other threads:[~2015-11-16 13:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-07 14:52 Reading data from a file descriptor Jan Synáček
2015-11-07 15:16 ` Artyom Poptsov
2015-11-07 15:29   ` Artyom Poptsov
2015-11-07 23:49     ` Andreas Rottmann
2015-11-09  7:25       ` Jan Synáček
2015-11-13 15:51         ` Mark H Weaver
2015-11-13 20:41           ` Jan Synáček
2015-11-13 20:45             ` Thompson, David
2015-11-15 11:09               ` Jan Synáček
2015-11-15 12:05                 ` Thompson, David
2015-11-16 10:54             ` Amirouche Boubekki
2015-11-17  9:53               ` tomas
2015-11-17 12:59                 ` Chris Vine
2015-11-17 12:52                   ` tomas
2015-11-17 13:55                     ` Chris Vine
2015-11-17 13:33                       ` tomas
2016-06-20 10:40                       ` Andy Wingo
2016-06-20 10:58                         ` tomas
2015-11-18  8:28                   ` Jan Synáček
2015-11-16 13:02           ` tomas [this message]
2015-11-23 21:07             ` Andreas Rottmann
2015-11-24 15:28               ` tomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151116130249.GA4154@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).