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: Tue, 17 Nov 2015 10:53:19 +0100	[thread overview]
Message-ID: <20151117095319.GA7958@tuxteam.de> (raw)
In-Reply-To: <09b3d3156d439ce3dd7bedc48d84fd5b@hypermove.net>

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

On Mon, Nov 16, 2015 at 11:54:33AM +0100, Amirouche Boubekki wrote:
> On 2015-11-13 21:41, Jan Synáček wrote:

[...]

> >I have an open fd to a unix socket and I want to read data from it. I
> >know that the data is going to be only strings, but I don't know the
> >length in advance.
> 
> Do you know a delimiter? maybe it's the null char?
> 
> TCP is stream oriented, it's not structured at this layer into messages
> or segments. You need some knowledge about the byte stream to be able to
> split it into different meaningful piece for the upper layer.

I think I "got" Jan's request, because I've been in a similar
situation before: delimiter is not (yet) part of it. What he's
looking for is an interface à la read(2), meaning "gimme as much
as there is in the queue, up to N bytes, and tell me how much
you gave me". Of course, putting stuff in a byte vector would
be preferable; the only functions I've seen[1] which "do" that
interface are read-string!/partial and write-string/partial
operate on strings, not byte arrays, alas.

> In Python the socket.recv method returns bytestring but still you
> have to parse
> to bytestring to make sure the delimiter is not in the middle of the
> string. What
> I mean is that in theory you might socket.recv the end of an
> application level message
> and the beginning of another using the same call.

Not (yet) about delimiters.

> Otherwise said, the only thing that could make sens for a (recv)
> procedure is
> to return the full content of the inbound network buffer for the
> given socket
> as a bytevector but it will still require work to to make things work...

Exactly, see above. A delimiter, or just feed the thing to an
incremental scanner/parser (e.g. a finite state machine, which
can get its input spoonwise).

> Have a look at the implementation. IMO the solution is to build a
> loop with
> (read-char) [1] looking for the *end char* to stop the loop.

If your application is set up to accept partial buffers of arbitraty
length, it seems a bit wasteful to have a buffered read (which is
definitely beneath `read-char') going through a character-wise
read into a new buffered read...

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

iEYEARECAAYFAlZK+Q8ACgkQBcgs9XrR2kaV6QCdFkPPiAZqhyC4knvJroGyq2+m
I0QAnicg8Cz5VL2I9VfWm7GcMLNhvNsM
=dk4d
-----END PGP SIGNATURE-----



  reply	other threads:[~2015-11-17  9:53 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 [this message]
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
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=20151117095319.GA7958@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).