Subject: Re: fifo & stdio ?
To: Hubert Feyrer <email@example.com>
From: Simon Burge <firstname.lastname@example.org>
Date: 06/14/1999 06:34:45
Hubert Feyrer wrote:
> I'm currently debugging gqmpeg's ipc system, and there's something I don't
> understand; maybe someone here can help me. I have an open file descriptor
> from a fifo (open(2)'ed with O_NONBLOCK), and i get a file pointer via
> fdopen(3) from that descriptor. I then want to check periodically if
> there's some data in the pipe, and do something else if not ("oink", in
> the program below).
> What I don't understand now is why I do not get any data when (trying to)
> read any available data with fgets(). feof() says we're at EOF after(!)
> the first call to fgets(), and doesn't change it's mind even after I send
> some data to the fifo ("echo bla >fifo.pipe").
> Is it possible our stdio is mixing something up here WRT pipes,
> buffering, eof, ...?
> Here's my test program. Compile it, and try to "echo some data
> >>fifo.pipe". The intention is to print out that data from the pipe.
> Instead, I just get:
> miyu% ./fifo
> fp=0x40093410, fd=3
> oink! feof=0
> oink! feof=1 <- "echo foo >>fifo.pipe" was done here
> oink! feof=1
If I were programming this I'd probably use select() and read() and not
stdio functions... That said, adding
if (feof(fp) != NULL)
after the "oink" printf() seems to give the behaviour you want.