On Mon, Apr 18, 2011 at 2:25 PM, Mike Meyer <m...@mired.org> wrote:

> Only if you also made the TCP/IP connection overhead trivial so you
> could stop with HTTP/1.0 and not deal with HTTP/1.1. Failing that, the
> most natural way to do this is:
>
> forever do
>        accept the next connection
>         handle requests from connection in new child
>               wait for next events
>               if one is a client request, start the response
>               if one is a finished response, return it to the client
>               if one is something else, something broke, deal with it.
>
> I.e, an event-driven loop for each incoming connection running in it's
> own process.
>

I'm not sure if I would call this "event driven", depending what's hiding
behind the sentences above. Here's how I've written servers that deal with
keep-alive, errors, etc.

server sock = forever $ do
    clientSock <- accept sock
    forkIO $ talk clientSock

talk sock = do
    maybeReq <- read sock
    case maybeReq of
        Nothing -> ... -- error while reading/parsing. Close socket or send
400 Bad Request
        Just req -> do
            resp <- handler req
            send sock resp
            when (isKeepAlive req) $ talk sock

The above code is executed efficiently using epoll but the programming model
is one with blocking system calls.

Johan
_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to