chicken-users
[Top][All Lists]
Advanced

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

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


From: Felix
Subject: Re: [Chicken-users] Request for a read-string! variant
Date: Thu, 15 Jul 2010 14:25:43 +0200 (CEST)

From: Alejandro Forero Cuervo <address@hidden>
Subject: [Chicken-users] Request for a read-string! variant
Date: Sun, 11 Jul 2010 13:03:30 +0200

> 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?

Currently not possible, but I see the point.

> 
> 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?

`read-string' currently reads a given number of characters or
everything up to EOF. If I understand correctly, you want to have a
mode that reads "as much as is currently available". Does this apply
to other port-types, besides network input?


cheers,
felix

reply via email to

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