[plt-scheme] no #!eof

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Apr 16 07:55:21 EDT 2008

At Wed, 16 Apr 2008 02:19:13 -0400, Neil Van Dyke wrote:
> Matthew Flatt wrote at 04/15/2008 07:51 AM:
> > At Tue, 15 Apr 2008 03:38:07 -0400, Neil Van Dyke wrote:
> >   
> >> Incidentally, in some experimenting just now, it seems the "sync" of PLT 
> >> 372 and 3.99.0.16 has the expected blocking behavior on a FIFO up until 
> >> the first EOF, but subsequently does not block on the FIFO.  If multiple 
> >> input segments are supported, should this EOF behavior in "sync" be changed?
> >>     
> >
> > I'm not suite sure what you mean. Can you provide an example?
> If I do these three things:
> 
> 1. Shell command: mkfifo /tmp/my-fifo
> 
> 2. Start this in MzScheme 372:
> 
> (let ((in (open-input-file "/tmp/my-fifo")))
>   (let loop ()
>     (sync in)
>     (printf "hit ~S\n" (read-byte in))
>     (loop)))
> 
> 3. Shell command: echo 123 > /tmp/my-fifo
> 
> Then the output from the MzScheme process will be:
> 
> hit 49
> hit 50
> hit 51
> hit 10
> hit #<eof>
> hit #<eof>
> hit #<eof>
> hit #<eof>
> hit #<eof>
> hit #<eof>
> [...]
> 
> Given the discussion yesterday, I'd expect "sync" to block after 
> printing the first "hit #<eof>", until I wrote more input to the FIFO, 
> but it no longer blocks after the first EOF.
> 
> I also see the same behavior when using "cat" to write incrementally to 
> the FIFO -- "sync" blocks as expected, until "cat" exits, then "sync" no 
> longer blocks.

When a writing process closes a FIFO, the other end gets only EOFs from
that point on. The infinite stream of EOFs is always ready, so that's
why `sync' keeps returning.

As far as I know, Unix pipes do not provide a way to send a mid-stream
EOF to the other end. But (again, as I understand it) a TTY is
something like a custom stream in the sense of `make-input-port', and
that's why it's able to turn Ctl-D into a mid-stream EOF.

Matthew



Posted on the users mailing list.