[Haskell-cafe] reliable (bi)directional pipe to a process

oleg at okmij.org oleg at okmij.org
Tue Nov 11 02:04:38 EST 2008

I'd like to point out a reliable, proven and simple way of interacting
with another process, via unidirectional or bidirectional pipes. The
method supports Unix sockets, pipes, and TCP sockets.

I too have noticed insidious bugs in GHC run-time when communicating
with another process via a pipe. I tried to use runInteractiveProcess;
it worked -- up to file sizes of about 300Kb. Then GHC run-time seems
to `loses synchronization' -- and corrupts IO buffers, receiving stuff
that cannot have been possibly sent. This is because handle operations
are asynchronous and the GHC scheduler seems to have race conditions.
That behavior was totally unacceptable. I was writing a production
code, and can't afford such errors.

Therefore, I wrote a simple foreign function interface to the code
sys_open that I have been using for about fifteen years. This code
does work, in production, for very large file sizes and long-running
processes, on many Unix and Unix-like systems. I was told once about a
Cygwin port.

Please see the test at the end of the file MySysOpen.hs. The test
interacts with another process over a bi-directional pipe, repeatedly
sending and receiving data. The amount of received data is large
(about 510K).

More information about the Haskell-Cafe mailing list