mirror of
https://github.com/zap-proto/haskell.git
synced 2026-10-30 15:05:00 +00:00
32 lines
800 B
Haskell
32 lines
800 B
Haskell
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
module Examples.Rpc.EchoServer (main) where
|
|
|
|
import Network.Simple.TCP (serve)
|
|
|
|
import Capnp (def, defaultLimit)
|
|
import Capnp.Rpc
|
|
( ConnConfig(..)
|
|
, Server
|
|
, handleConn
|
|
, pureHandler
|
|
, socketTransport
|
|
, toClient
|
|
)
|
|
|
|
import Capnp.Gen.Echo.Pure
|
|
|
|
data MyEchoServer = MyEchoServer
|
|
|
|
instance Server IO MyEchoServer
|
|
instance Echo'server_ IO MyEchoServer where
|
|
echo'echo = pureHandler $ \MyEchoServer params ->
|
|
pure def { reply = query params }
|
|
|
|
main :: IO ()
|
|
main = serve "localhost" "4000" $ \(sock, _addr) ->
|
|
handleConn (socketTransport sock defaultLimit) def
|
|
{ debugMode = True
|
|
, getBootstrap = \sup -> Just . toClient <$> export_Echo sup MyEchoServer
|
|
}
|