[Haskell-cafe] Reading from a process

Jason Dusek jason.dusek at gmail.com
Wed Dec 16 17:25:02 EST 2009


2009/12/16 Mitar <mmitar at gmail.com>:
> The problem is that I do not like this approach. And it does not look
> nice. For example I am reading byte per byte and appending it to the
> end. Then the problem is that if process is sending garbage faster
> then Haskell can consume it Haskell stays in slurpInput function and
> never gets to readData where it would found out that there is garbage
> coming in. I could use hGetBufNonBlocking? But it would still not
> solve garbage problem.

  The what is a solid, terminating criterion for garbage? How do
  you know this stream of bytes is no good or has gone as far as
  you can allow it to go? Use that criterion in `slurpInput`.

> So is there some better way to do it?

  I urge you to reconsider your approach for message delimiting.
  Why use the `hReady` signal as the clue? Seems like a race
  condition waiting to happen. Maybe terminate them with a
  Haskell comment, like `-- EOT`. Since your message always
  comes wrapped in a list, you could just use the square
  brackets to tell you when you're done.

--
Jason Dusek


More information about the Haskell-Cafe mailing list