--
-- Example:
--
--- > {-# LANGUAGE OverloadedStrings #-}
--- > {-# LANGUAGE QuasiQuotes #-}
--- > module Main where
--- > import Network
--- > import Network.HTTP.Lucu
--- >
--- > main :: IO ()
--- > main = let config = defaultConfig
--- > resources = mkResTree [ ([], helloWorld) ]
--- > in
--- > withSocketsDo $ runHttpd config resourcees []
--- >
--- > helloWorld :: Resource
--- > helloWorld = emptyResource {
--- > resGet
--- > = Just $ do setContentType [mimeType| text/plain |]
--- > putChunk "Hello, world!"
--- > }
--- FIXME: update the above example
-runHttpd ∷ Config → SchemeMap → IO ()
-runHttpd cnf sm
+-- @
+-- {-\# LANGUAGE OverloadedStrings \#-}
+-- {-\# LANGUAGE QuasiQuotes \#-}
+-- module Main where
+-- import qualified "Data.Collections" as C
+-- import "Network"
+-- import "Network.HTTP.Lucu"
+--
+-- main :: 'IO' ()
+-- main = let config = 'defaultConfig'
+-- tree :: 'ResourceTree'
+-- tree = C.fromList [ ([], 'nonGreedy' helloWorld) ]
+-- in
+-- 'Network.withSocketsDo' '.' 'runHttpd' config '$' 'resourceMap' tree
+--
+-- helloWorld :: 'Network.HTTP.Lucu.Resource'
+-- helloWorld = C.fromList
+-- [ ( 'Network.HTTP.Lucu.GET'
+-- , do 'Network.HTTP.Lucu.setContentType' ['Network.HTTP.Lucu.mimeType'| text/plain |]
+-- 'Network.HTTP.Lucu.putChunk' \"Hello, world!\"
+-- }
+-- @
+runHttpd ∷ HostMapper α ⇒ Config → α → IO ()
+runHttpd cnf hm
= do let launchers
= catMaybes
[ do addr ← cnfServerV4Addr cnf
httpLoop port so
= do (h, addr) ← SL.accept so
tQueue ← mkInteractionQueue
- readerTID ← forkIO $ requestReader cnf sm h port addr tQueue
+ readerTID ← forkIO $ requestReader cnf hm h port addr tQueue
_writerTID ← forkIO $ responseWriter cnf h tQueue readerTID
httpLoop port so