Re: use of select() on FIFO after it has closed Alex Fraser wrote:
> An alternative is to open the FIFO for writing immediately after opening it
> for reading, and leave both descriptors open (opening it O_RDWR may work;
> the behaviour is unspecified by POSIX). This means you will never see EOF
> (useful in some cases).
I went this route. Now it opens the file, checks the fd with fstat() to
see if it is a FIFO, and if it is, it opens the same file for write.
Unfortunately it (still) locks on the first open() of the FIFO unless
there is already data waiting there. I do not think there is a way
around that, since the program cannot set read nonblocking until it has
a read fd, and it cannot get a read fd until the file is opened. The
program could use stat() first to see if it is a FIFO before opening it
for read, and do the open for write first, then push a byte or two into
the FIFO so the open for read won't block. But that isn't safe, since
the program has no way of knowing if there is data in the FIFO at that
point. Better to live with the block on open for read I guess.
Thanks,
David Mathog |