on master help sign in
use more specific type for server->client sendMessage
commit1e60c0580ca33d6ae1e97aaddc32189fdfe3ef6c authorAgentM <agentm@themactionfaction.com> dateFri 25 Dec 2020, 21:36 (6 years ago) parentf67c45d
2 files changed+7−6
src/Network/RPC/Curryer/Server.hs+6−5 test/Curryer/Test/Basic.hs+1−1
src/Network/RPC/Curryer/Server.hs+6−5
@@ -111,13 +111,14 @@ data ConnectionState a = ConnectionState {
111111 connectionSocket :: Locking Socket
112112 }
113113
114−-- | Used by server-side request handlers to send additional messages to the client. This is useful for sending asynchronous responses to the client outside of the normal request-response flow.
115−sendMessage :: Serialise a => ConnectionState s -> a -> IO ()
116−sendMessage sState msg = do
114+-- | Used by server-side request handlers to send additional messages to the client. This is useful for sending asynchronous responses to the client outside of the normal request-response flow. The locking socket can be found in the ConnectionState when a request handler is called.
115+sendMessage :: Serialise a => Locking Socket -> a -> IO ()
116+sendMessage lockSock msg = do
117117 requestID <- UUID <$> UUIDBase.nextRandom
118118 let env =
119− Envelope (fingerprint msg) (RequestMessage 0) requestID (serialise msg)
120− sendEnvelope env (connectionSocket sState)
119+ Envelope (fingerprint msg) (RequestMessage timeout) requestID (serialise msg)
120+ timeout = 0
121+ sendEnvelope env lockSock
121122
122123--avoid orphan instance
123124newtype UUID = UUID { _unUUID :: UUIDBase.UUID }
test/Curryer/Test/Basic.hs+1−1
@@ -78,7 +78,7 @@ testServerRequestHandlers mAsyncMVar =
7878 maybe (pure ()) (\mvar -> putMVar mvar v) mAsyncMVar
7979 -- an async hello to the server generates an async hello to the client
8080 , AsyncRequestHandler $ \sState (AsyncHelloReq s) -> do
81− sendMessage sState (AsyncHelloReq s)
81+ sendMessage (connectionSocket sState) (AsyncHelloReq s)
8282
8383 , RequestHandler $ \_ (RoundtripStringReq s) -> pure s
8484 , RequestHandler $ \_ (DelayMicrosecondsReq ms) -> do