[Haskell-cafe] I/O system brokenness with named pipes

John Goerzen jgoerzen at complete.org
Fri Apr 11 08:12:59 EDT 2008

On Friday 11 April 2008 05:39:54 am Duncan Coutts wrote:
> On Thu, 2008-04-10 at 20:34 -0500, John Goerzen wrote:
> > I have created the named pipe from Haskell no problem.
> >
> > But I can't use writeFile to write data to it.  Worse, it returns:
> >
> > *** Exception: /tmp/bakroller.zD0xHj/fifo: openFile: does not exist
> >     (No such device or address)
> >
> > What's going on here?  Am I going to have to resort to the
> > System.Posix interface just to be able to write to a named pipe?
> Named pipes have broken semantics for non-blocking IO, see google or the
> man pages on named pipes. GHC's standard Handle IO always sets file
> descriptor to non-blocking mode. That's the problem. That's why cat
> works, because it uses blocking IO.

OK, I have referred to fifo(7) regarding this point.  It seems I may need a 
loop trying over and over to open the FIFO in write mode.  It also appears 
that ReadWriteMode appearing to work is Linux-specific, and this behavior is 
left undefined in POSIX.

Does openFd do a non-blocking open?  (Brief testing suggests it does) I'm 
somewhat confused about its semantics, especially since it does not appear 
to correspond directly to open(2).  O_CREAT, for instance, is missing.  

> You would indeed need to use System.Posix to get a FD in blocking mode.
> Then you have to worry a bit about blocking other Haskell thread when
> you block on writing to the pipe.

Fortunately, in this particular case, I'm using forking instead of threading 
so this won't be a problem.

Thanks for the help.

-- John

More information about the Haskell-Cafe mailing list