]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Httpd.hs
Many improvements: still in early development
[Lucu.git] / Network / HTTP / Lucu / Httpd.hs
1 module Network.HTTP.Lucu.Httpd
2     ( runHttpd        -- Config -> ResTree -> IO ()
3     )
4     where
5
6 import           Control.Concurrent
7 import           Control.Concurrent.STM
8 import qualified Data.ByteString.Lazy.Char8 as B
9 import           Data.ByteString.Lazy.Char8 (ByteString)
10 import           Network
11 import           Network.HTTP.Lucu.Config
12 import           Network.HTTP.Lucu.Interaction
13 import           Network.HTTP.Lucu.RequestReader
14 import           Network.HTTP.Lucu.Resource
15 import           Network.HTTP.Lucu.ResponseWriter
16 import           System.IO
17
18
19 runHttpd :: Config -> ResTree -> IO ()
20 runHttpd cnf table
21     = withSocketsDo $
22       do so <- listenOn (cnfServerPort cnf)
23          loop so
24     where
25       loop :: Socket -> IO ()
26       loop so
27           = do (h, host, _) <- accept so
28                tQueue       <- newInteractionQueue
29                forkIO $ requestReader cnf table h host tQueue
30                forkIO $ responseWriter h tQueue
31                loop so