
Thank you very much, it works :)
As I think it might be of help to the others, I'm cc'ing this mail
to the mailing list where my question was initially posted with the
revised code attached.
Sincerely,
Jerry
* Simon Marlow
[ redirected to glasgow-haskell-bugs@haskell.org ]
Good day everyone, I was fiddling around with this tiny echo client/server haskell program from 'The Great Language Shootout' site (http://www.bagley.org/~doug/shootout/) and got stuck.
The code (attached) has been reformatted with minimal API tweak (mkPortNumber, writeSocket, readSocket) to please my ghc-5.02.2, and all what I get is something stuck forever after the first iteration:
$ ./echo 3 Client wrote: Hello there sailor Server recv: Hello there sailor Server read: Hello there sailor Server wrote: Hello there sailor
After adding all these print statement, I still don't have a clue what's jammed there. Hope someone here can shred some light.
It turns out to be a bug in the network library; we weren't putting the socket returned from accept into non-blocking mode. It works fine if you use Handles rather than send/recv because the act of making a Handle from a file descriptor sets non-blocking mode on the FD, so a workaround for your program is just to insert a call to socketToHandle on the socket returned from accept (you don't have to use the Handle, just calling socketToHandle has the desired effect).
Thanks for the report.
BTW, I'd also like to take this chance to ask how to debug a haskell program in general?
With putStr or IOExts.trace, or using one of the more sophisticated debugging tools such as the nhc98 tracing system or Andy Gill's Observe library. You should be able to find links on the www.haskell.org pages to these projects.
Cheers, Simon