View Single Post
  #4  
Old 02-26-2008, 03:05 AM
unix unix is offline
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default Re: use of select() on FIFO after it has closed

In article ,
David Mathog wrote:

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


Does the O_NONBLOCK option to open(2) help?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Reply With Quote