guile-user
[Top][All Lists]
Advanced

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

Re: drain-input


From: Gary Houston
Subject: Re: drain-input
Date: 24 Aug 2001 17:20:04 -0000

> From: Alex Shinn <address@hidden>
> Date: 24 Aug 2001 11:11:05 -0400
> 
> Could someone explain the purpose of drain-input?  My first impression
> was that it would read all remaining input from an input port, so that
> you could do the following:
> 
> (define (file-contents file)
>   (call-with-input-file file drain-input))
> 
> but this doesn't work, and on playing with drain-input it seems to be
> working more with the internal port buffering.  For example:
> 
> (define p (open-input-file foo))   ; str is
> (define str (drain-input p))       ; ""
> (unread-char #\x p)
> (set! str (drain-input p))         ; "x"
> (set! str (drain-input p))         ; ""
> (peek-char p)
> (set! str (drain-input p))         ; entire contents of foo
> 
> Is this the correct behaviour?  What is drain-input really doing?

It's returning the contents of the port input buffers.  It's possibly
useful for syncing buffered input for operations that act directly
on the file descriptor.

> (set! str (drain-input p))         ; entire contents of foo

Only if less than the buffer size, typically 4096 bytes.



reply via email to

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