[Haskell-cafe] A simple telnet client using Conduit

Erik de Castro Lopo mle+hs at mega-nerd.com
Thu Jan 12 02:12:24 CET 2012


Felipe Almeida Lessa wrote:

> What about inverting which thread gets to do what?
> 
>   _ <- resourceForkIO $ sourceHandle hsock $$ sinkHandle stdout
>   sourceHandle stdin $$ sinkHandle hsock
>   release releaseSock

Thats an interesting idea. Unfortunately this doesn't work correctly
in that if the server disconnects, the client doesn't detect it and
hangs with one end of the connection closed.

> Actually, I'm not sure if my solution is better or worse than yours.
> The question is "how long does it take for the thread to die after
> hsock gets closed?"  If the answer is "right away", then my solution
> is simpler =).  Otherwise, you solution is less resource-hungry.

Well GHC runtime threads are very cheap while sockets/file descriptors
are in comparison a very much limited resource. That means that code
should be written to clean up sockets/fds in preference to cleaning
up threads.

Cheers,
Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/



More information about the Haskell-Cafe mailing list