[Haskell-cafe] Waiting on input with `hWaitForInput' or `threadWaitRead'
es at ertes.de
Mon Oct 17 10:58:11 CEST 2011
Jason Dusek <jason.dusek at gmail.com> wrote:
> I would like to use evented I/O for a proxying application. My present
> thinking is to fork a thread for each new connection and then to wait
> for data on either socket in this thread, writing to one or the other
> socket as needed.
> Ideally, I'd get something like select() on handles, just saying
> whether there are bytes or not. However, I haven't managed to find
> anything like that in the standard libraries.
I don't think you want either of the functions you mentioned. What you
probably want instead is to do concurrent programming by creating
Haskell threads. A hundred Haskell threads reading from Handles are
translated to one or more OS threads using whatever polling mechanism
(select(), poll(), epoll) your operating system supports.
I have uploaded a simple concurrent echo server implementation to hpaste
. It uses one thread for the stdout logger, one thread for the
server, one thread for each client and finally a main thread waiting for
you to hit enter to quit the application.
 http://hpaste.org/52742 - Concurrent echo server with logger
nightmare = unsafePerformIO (getWrongWife >>= sex)
More information about the Haskell-Cafe