Network, sClose

Jon Fairbairn Jon.Fairbairn at
Sat Aug 14 10:15:26 EDT 2004

On 2004-08-13 at 21:53BST Glynn Clements wrote:
> Simon Marlow wrote:
> > Yes, I'm sure that's the reason for it.  Proposals for a replacement are
> > welcome...
> What would be the intended purpose of a replacement?
> If you want a simpler interface for writing servers, it would probably
> look something like:
> 	doServer :: PortID -> (Handle -> IO ()) -> IO ()
> 	doServer port handler = do
> 		s <- listenOn port
> 		let doIt = do
> 			~(s', _)  <-  Socket.accept s
> 			h <- socketToHandle s' ReadWriteMode
> 			forkIO $ handler h >> hClose h

Shouldn't there be sCloses in here?

> 		sequence_ $ repeat doIt

Otherwise that looks like a much handier thing, though there
/might/ be call for something without the forkIO.

> Ultimately, you either need to create a separate thread/process per
> connection, or manually service multiple connections (select/poll). A
> server which processed connections sequentially wouldn't be of much
> practical use

Well, for the to application I had in mind when I started
this thread, sequential processing of connexions is exactly
what's wanted. Whoever makes the first connexion gets
control and keeps it until they drop the connexion, then the
next client takes over.

> (and a one-shot server probably wouldn't even be of use
> for "toy" programs).

Indeed not!

Jón Fairbairn                                 Jon.Fairbairn at

More information about the Glasgow-haskell-users mailing list