[Haskell-cafe] Socket Programming

Chris Kuklewicz haskell at list.mightyreason.com
Tue Jan 2 15:20:19 EST 2007

Mark Goldman wrote:
> I am trying to write a toy echo server that can handle multiple
> connections.  I would like to be able to test and see if there are any
> connections waiting to be accepted on a socket.  In C and related
> languages I would use something like select or poll to be nice to the
> OS, what would I use with the current haskell libs given that I can't
> seem to find a function to test if accept would block or not?
> -mdg

The wiki page http://haskell.org/haskellwiki/Concurrency_demos/Graceful_exit
uses accepting connections as its example.

The main idea is use accept (which blocks) in a background thread and which
provides the resulting connections to some inter-thread data stream: MVar,
MChan, TMVar, TChan, or your own structure.

Shutting down a system is usually subtle, and that wiki page concentrates on a
trying to create a solution which provides dependable shutdown semantics.

More information about the Haskell-Cafe mailing list