-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathServer.hs
35 lines (29 loc) · 1.29 KB
/
Server.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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.String (fromString)
import Network.ABCI.Server.App (App (..))
import qualified Network.ABCI.Server.App as App
-- | Default ABCI app network settings for serving on localhost at the
-- standard port.
defaultLocalSettings :: ServerSettings
defaultLocalSettings = serverSettings 26658 $ fromString "0.0.0.0"
-- | Serve an ABCI application with custom 'ServerSettings' and a custom
-- action to perform on acquiring the socket resource.
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
-- | Serve an ABCI application with default local 'ServerSettings'
-- and a no-op on acquiring the socket resource.
serveApp :: App IO -> IO ()
serveApp = serveAppWith defaultLocalSettings mempty