module Network.ABCI.Server where
import Data.Conduit (runConduit, (.|))
import qualified Data.Conduit.List as CL
import Data.Conduit.Network (AppData, ServerSettings, appSink,
appSource, runTCPServer,
serverSettings)
import Data.Monoid (mempty)
import Data.String (fromString)
import Network.ABCI.Server.App (App (..))
import qualified Network.ABCI.Server.App as App
defaultLocalSettings :: ServerSettings
defaultLocalSettings = serverSettings 26658 $ fromString "0.0.0.0"
serveAppWith
:: ServerSettings
-> (AppData -> IO ())
-> App IO
-> IO ()
serveAppWith cfg onAquire app = runTCPServer cfg $ \appData -> do
onAquire appData
runConduit $ appSource appData
.| CL.mapM (fmap App.unLPByteStrings . App.runApp app . App.LPByteStrings)
.| appSink appData
serveApp :: App IO -> IO ()
serveApp = serveAppWith defaultLocalSettings mempty