unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: mark@markwitmer.com
Cc: guile-user@gnu.org
Subject: Re: asynchronous socket library
Date: Wed, 17 Jul 2013 03:13:33 -0400	[thread overview]
Message-ID: <8738rd1wwy.fsf@tines.lan> (raw)
In-Reply-To: <8761w9n2i6.fsf@mark-desktop.PK5001Z> (mark@markwitmer.com's message of "Tue, 16 Jul 2013 23:07:13 -0700")

mark@markwitmer.com writes:
> Reading and writing to a socket seems to lend itself well to custom
> binary ports,

Why do you say that?  For most purposes, Guile's native file ports are
superior, and they seem the natural choice for sockets.

> but then I think you're stuck with an opaque buffer -- you
> can't properly ask the binary port if the next read beyond one byte will
> block or not, since it might have stuff buffered or it might not. I'd
> love to be wrong about that if someone happens to know how to check for
> the amount remaining in a custom binary port's buffer.

'get-bytevector-some' from (rnrs io ports) might do what you need.  If
there's at least one byte available it will not block, but in practice
it reads much more than that (for buffered ports).  Guile 2.0.9 has a
nice fast implementation.  Prior to 2.0.9, it was less so.

In more detail: as of 2.0.9, 'get-bytevector-some' will simply copy the
input buffer managed by Guile into a bytevector and return it.  If
Guile's input buffer is empty, it will try to refill the buffer using
the port type's 'fill_input' method.  For file ports this is
fports.c:fport_fill_input, and for custom binary ports it's
r6rs-ports.c:cbip_fill_input.

Prior to 2.0.9, 'get-bytevector-some' was instead implemented as a loop
that repeatedly called 'char-ready?' and read one byte at a time.  This
would drain more than just Guile's buffer; it would try to drain the
upstream buffers as well.

However, 'char-ready?', and thus the pre-2.0.9 'byte-vector-some',
depend upon the port type providing an 'input_waiting' method.  File
ports provide this, implemented using 'poll' with 0 timeout, see
fports.c:fport_input_waiting.

Unfortunately, custom binary ports do NOT provide an 'input_waiting'
method, so 'char-ready?' always returns true, and I guess this
ultimately means that the pre-2.0.9 'get-bytevector-some' will block
until it reaches EOF.

So again I ask, why use custom binary ports for sockets?

    Regards,
      Mark



  reply	other threads:[~2013-07-17  7:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15 23:41 asynchronous socket library Aleix Conchillo Flaqué
2013-07-16  1:03 ` Nala Ginrut
2013-07-16  1:42   ` Aleix Conchillo Flaqué
2013-07-16  6:15 ` Javier Sancho
2013-07-16  7:02   ` Aleix Conchillo Flaqué
2013-07-16  7:03     ` Aleix Conchillo Flaqué
2013-07-16  7:36     ` Chaos Eternal
2013-07-16 15:24       ` Aleix Conchillo Flaqué
2013-07-16 15:58         ` Chaos Eternal
2013-07-16 17:02           ` Aleix Conchillo Flaqué
2013-07-16  7:50     ` Thien-Thi Nguyen
2013-07-16 15:26       ` Aleix Conchillo Flaqué
2013-07-17  6:07 ` mark
2013-07-17  7:13   ` Mark H Weaver [this message]
2013-07-17 16:49     ` mark
2013-08-24 21:33       ` Mark H Weaver
2013-08-25 22:26         ` mark.d.witmer

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=8738rd1wwy.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=guile-user@gnu.org \
    --cc=mark@markwitmer.com \
    /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).