Skip to content

Commit 9c06c4c

Browse files
committed
dmq-node: localMsgNotification - do not enforce protocol invariants
1 parent ea14d58 commit 9c06c4c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

dmq-node/src/DMQ/NodeToClient/LocalMsgNotification.hs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module DMQ.NodeToClient.LocalMsgNotification where
1+
module DMQ.NodeToClient.LocalMsgNotification
2+
( localMsgNotificationServer
3+
, LocalMsgNotificationProtocolError (..)
4+
) where
25

36
import Control.Concurrent.Class.MonadSTM
47
import Control.Monad.Class.MonadThrow
@@ -23,19 +26,10 @@ instance Exception LocalMsgNotificationProtocolError where
2326
displayException ProtocolErrorUnexpectedNonBlockingRequest =
2427
"The client issued a non-blocking request when a blocking request was expected."
2528

26-
2729
-- | Local Message Notification server application
2830
--
29-
-- enforced protocol invariants:
30-
--
31-
-- * non-blocking requests are only accepted when the server has no more messages,
32-
-- client is aware of this from previous replies
33-
-- * dually, blocking requests are only accepted when the server has more
34-
-- messages.
35-
-- * the first request must be blocking
36-
--
3731
localMsgNotificationServer
38-
:: forall m msg msgid idx a. (MonadSTM m, MonadThrow m)
32+
:: forall m msg msgid idx a. (MonadSTM m {-, MonadThrow m -})
3933
=> Tracer m (TraceMessageNotificationServer msg)
4034
-> m a
4135
-> Word16
@@ -51,7 +45,7 @@ localMsgNotificationServer tracer mdone maxMsgs0
5145
maxMsgs = fromIntegral maxMsgs0
5246

5347
serverIdle :: idx -> HasMore -> ServerIdle m msg a
54-
serverIdle !lastIdx hasMore = ServerIdle { msgRequestHandler, msgDoneHandler }
48+
serverIdle !lastIdx _hasMore = ServerIdle { msgRequestHandler, msgDoneHandler }
5549
where
5650
msgRequestHandler :: forall blocking.
5751
SingBlockingStyle blocking
@@ -67,8 +61,8 @@ localMsgNotificationServer tracer mdone maxMsgs0
6761
in (lastIdx', hasMore', msgs)
6862
case blocking of
6963
SingBlocking
70-
| HasMore <- hasMore ->
71-
throwIO ProtocolErrorUnexpectedBlockingRequest
64+
-- | HasMore <- hasMore ->
65+
-- throwIO ProtocolErrorUnexpectedBlockingRequest
7266
| otherwise -> do
7367
(lastIdx', hasMore', msgs) <- atomically do
7468
snapshot <- mempoolGetSnapshot
@@ -81,8 +75,8 @@ localMsgNotificationServer tracer mdone maxMsgs0
8175
hasMore'
8276
(serverIdle lastIdx' hasMore')
8377
SingNonBlocking
84-
| DoesNotHaveMore <- hasMore ->
85-
throwIO ProtocolErrorUnexpectedNonBlockingRequest
78+
-- | DoesNotHaveMore <- hasMore ->
79+
-- throwIO ProtocolErrorUnexpectedNonBlockingRequest
8680
| otherwise -> do
8781
snapshot <- atomically mempoolGetSnapshot
8882
let (lastIdx', hasMore', msgs) = process snapshot

0 commit comments

Comments
 (0)