Reading/Writing sockets concurrently
dolk at dtek.chalmers.se
Thu Dec 9 12:46:07 EST 2004
I'm trying to create a client application that needs to read and write
data from a socket. What I want to do is to have one thread reading the
socket and another thread writing to the same socket, but I can't get it
I know that there is a problem with having two threads reading from the
same Handle (as in the aaaa bbbb example), due to the locking. To avoid
this blocking I open the socket with Network.Socket.socket and create
two handles with socketToHandle, one in ReadMode and one in WriteMode.
But the threads still seem to be blocking each other and the program
runs very slowly. I am using channels to have the read and write threads
communicate with other threads in the application and by removing a
writeChan in one of these other threads the program crashes with a
"Fail: thread blocked indefinitely".
Are there any good examples of how to use sockets with Haskell. I have
no way of knowing in which order I will need to read data from and write
data to the socket.
I am using ghc version 6.2.2 on Linux.
Thanks in advance
More information about the Glasgow-haskell-users