Reading/Writing sockets concurrently

Mårten Dolk dolk at dtek.chalmers.se
Fri Dec 10 05:54:46 EST 2004


Hi!

Thanks for the reply!

ajb at spamcop.net wrote:

>>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
>>to work.
>>    
>>
>
>You could take a look at lambdabot:
>
>        http://www.scannedinavian.org/repos/lambdabot/lambdabot/
>
>It has a two-thread structure similar to what you appear to need.  Look
>in IRC.hs specifically.
>
>  
>
That code looked very much like what I was trying to do. The difference? 
I had my writer loop running in the main thread. Forking the writer to 
its own thread did take care of the evil "Fail: thread blocked 
indefinitely". But I'm still not sure about the scheduling/blocking 
issue. You do seem to have one thread reading to the same handle as 
another thread is reading. Isn't that a problem?

Well, the code works well enough for my purposes now. :)

Btw, you import GHC.IO and not System.IO. What is the diffrence between 
those two?

Thanks,
Mårten



More information about the Glasgow-haskell-users mailing list