Files
Ian Denhardt 33f1126948 Add SomeServer base class to new API.
Analogue of Server in the old API (the name for which is taken by the
type constraint alias in Export).
2021-08-05 18:07:18 -04:00

27 lines
817 B
Haskell

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module Examples.Rpc.EchoServer (main) where
import Network.Simple.TCP (serve)
import Capnp.New (SomeServer, def, defaultLimit, export, handleParsed)
import Capnp.Rpc (ConnConfig(..), handleConn, socketTransport, toClient)
import Capnp.Gen.Echo.New
data MyEchoServer = MyEchoServer
instance SomeServer MyEchoServer
instance Echo'server_ MyEchoServer where
echo'echo MyEchoServer = handleParsed $ \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
}