writing to a fifo when the reader stops reading

Hi all, here's the code: writer = do threadDelay 100000 threadWaitWrite fd fdWrite fd ((show x) ++ "\n") writer fd (x+1) pretty simple, it just keeps writing. What happens though is that, eventually, the reader goes away, i.e. "closes" the fifo. When that happens I get: ghc: fdWriteBuf: resource vanished (Broken pipe) which make sense, sort of. I write a value, let's say 10, and the reader reads it. It's the last value so it "closes" the fifo. Now there's nothing reading, so when I get to threadWaitWrite, I would expect the program to wait, just as it does when it starts up and there is no reader. looking for some guidance. Thank you, Brian

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 3/13/11 03:16 , briand@aracnet.com wrote:
ghc: fdWriteBuf: resource vanished (Broken pipe)
which make sense, sort of. I write a value, let's say 10, and the reader reads it. It's the last value so it "closes" the fifo.
Now there's nothing reading, so when I get to threadWaitWrite, I would expect the program to wait, just as it does when it starts up and there is no reader.
FIFOs don't work that way; like a regular pipe, once all readers go away it doesn't work any more. You need to open it read-write initially to keep a reader around. Haskell has no control over this: it's how they're defined to work. In general, trying to use a FIFO like an AF_UNIX socket is a mistake. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery.b@gmail.com system administrator [openafs,heimdal,too many hats] kf8nh -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk19tqkACgkQIn7hlCsL25VxGwCgsInAy4YJhOA2Ca/tQTRd0Cjs NmAAn2hjqtQm0/eZXVoLM8GMCMv+yxR4 =SDd8 -----END PGP SIGNATURE-----

On Mon, 14 Mar 2011 02:33:13 -0400
Brandon S Allbery KF8NH
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 3/13/11 03:16 , briand@aracnet.com wrote:
ghc: fdWriteBuf: resource vanished (Broken pipe)
which make sense, sort of. I write a value, let's say 10, and the reader reads it. It's the last value so it "closes" the fifo.
Now there's nothing reading, so when I get to threadWaitWrite, I would expect the program to wait, just as it does when it starts up and there is no reader.
FIFOs don't work that way; like a regular pipe, once all readers go away it doesn't work any more. You need to open it read-write initially to keep a reader around. Haskell has no control over this: it's how they're defined to work.
ok, I wanted to make sure that I wasn't missing something on the Haskell side.
In general, trying to use a FIFO like an AF_UNIX socket is a mistake.
and using a socket doesn't really make sense because everything is running on the same host, always will be, and using sockets will unnecessarily complicate things. although it's not that bad and works really well. I'll go figure out a different strategy. Thank you, Brian

On Mon, Mar 14, 2011 at 9:44 AM,
On Mon, 14 Mar 2011 02:33:13 -0400 Brandon S Allbery KF8NH
wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 3/13/11 03:16 , briand@aracnet.com wrote:
ghc: fdWriteBuf: resource vanished (Broken pipe)
which make sense, sort of. I write a value, let's say 10, and the reader reads it. It's the last value so it "closes" the fifo.
Now there's nothing reading, so when I get to threadWaitWrite, I would expect the program to wait, just as it does when it starts up and there is no reader.
FIFOs don't work that way; like a regular pipe, once all readers go away it doesn't work any more. You need to open it read-write initially to keep a reader around. Haskell has no control over this: it's how they're defined to work.
ok, I wanted to make sure that I wasn't missing something on the Haskell side.
In general, trying to use a FIFO like an AF_UNIX socket is a mistake.
and using a socket doesn't really make sense because everything is running on the same host, always will be, and using sockets will unnecessarily complicate things. although it's not that bad and works really well.
I think the prior emailer was recommending file sockets, not TCP sockets: http://en.wikipedia.org/wiki/Unix_domain_socket These only work on the same host.
I'll go figure out a different strategy.
Thank you,
Brian
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Antoine Latter
-
Brandon S Allbery KF8NH
-
briand@aracnet.com