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

matth at mindspring.com matth at mindspring.com
Sat Jul 5 22:35:52 EDT 2008

On Fri, Apr 11, 2008 at 12:39:54PM +0200, 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.
> 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.

You could also work around this, at least on Linux, by opening the file
in ReadMode before opening it in WriteMode.  Hold the reading file
handle open until you close the writing handle.  Never read from the
reading handle.  In my testing, this worked well, but bear in mind that
when the other readers close the pipe, further writes will "block"
rather than produce a SIGPIPE.


More information about the Haskell-Cafe mailing list