chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Request for a read-string! variant


From: Alejandro Forero Cuervo
Subject: [Chicken-users] Request for a read-string! variant
Date: Sun, 11 Jul 2010 13:03:30 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

I want to write something akin to the following C code:

  char buffer[BUFSIZ];
  int len;
  while (0 < (len = read(fd, buffer, BUFSIZ))) {
    consume(buffer, len);
  }

I'd rather not consume characters one by one —as I'm somewhat
concerned with efficiency— but, on the other hand, I would rather
consume inputs as soon as they are available to my process (because
the file descriptor may be a socket, which may wait for a reaction on
something it sent before sending more).

What would be the recommended way to do this in Chicken Scheme?

I noticed that there is a read-string! function but, upon inspecting
its source, it seems to, inconveniently, iterate until it has filled
the buffer provided (as opposed to just returning as soon as
fast_read_string_from_file has returned).  Maybe we should make
read-string and read-string! just return after
fast_read_string_from_file, rather than iterate?  Given that the
caller already has to deal with fewer characters returned than
requested (since the EOF may have been reached), I think this would
provide a much better interface (since it would also support my use
case).  If there's concern about backwards compatibility, could a new
function with this behavior be provided?

Thanks!

Alejo.
http://azul.freaks-unidos.net/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]