Hi Patrick,<br><br><div class="gmail_quote">On Fri, Sep 10, 2010 at 2:02 PM, Patrick LeBoutillier <span dir="ltr"><<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">In order to get better at network programming using haskell, I'd like<br>
to try and port it to Haskell, but I can't seem to locate the<br>
equivalent to select(2) in Haskell. Perhaps a different idiom is to be<br>
used?<br></blockquote></div><br>GHC uses select/epoll/kqueue internally to multiplex its lightweight threads. When you would use a select loop for handle many connections in one language you would typically launch one thread per connection in Haskell, using forkIO. With the upcoming version GHC can handle 100k+ threads this way. Right now the limit is 1024 simultaneous connections due a hard coded limit in select.<br>
<br>You code would look something like this:<br><br>acceptConnections serverSock = do<br> sock <- accept severSock<br> forkIO $ handleConnection sock<br> acceptConnections serverSock<br><br>handleConnection sock = do<br>
msg <- recv<br> send ...<br> sClose sock<br><br>I'd recommend using the network-bytestring library which provides more efficient versions of e.g. recv and send.<br><br>Cheers,<br>Johan<br><br>