summaryrefslogtreecommitdiff
path: root/src/Data/PacketQueue.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/PacketQueue.hs')
-rw-r--r--src/Data/PacketQueue.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Data/PacketQueue.hs b/src/Data/PacketQueue.hs
index 57845ae5..f1be1375 100644
--- a/src/Data/PacketQueue.hs
+++ b/src/Data/PacketQueue.hs
@@ -10,6 +10,7 @@ module Data.PacketQueue
10 , new 10 , new
11 , newOverwrite 11 , newOverwrite
12 , dequeue 12 , dequeue
13 , getMissing
13 , dequeueOrGetMissing 14 , dequeueOrGetMissing
14 , markButNotDequeue 15 , markButNotDequeue
15 , enqueue 16 , enqueue
@@ -99,14 +100,27 @@ observeOutOfBand PacketQueue { seqno, qsize, buffend } numberOfNextLosslessPacke
99 100
100-- | If seqno < buffend then return expected packet numbers for all 101-- | If seqno < buffend then return expected packet numbers for all
101-- the Nothings in the array between them. 102-- the Nothings in the array between them.
103-- Otherwise, return empty list.
104getMissing :: PacketQueue a -> STM [Word32]
105getMissing PacketQueue { pktq, seqno, qsize, buffend } = do
106 seqno0 <- readTVar seqno
107 buffend0 <- readTVar buffend
108 -- note relying on fact that [ b .. a ] is null when a < b
109 maybes <- mapM (readArray pktq) (take (fromIntegral qsize) $ map (`mod` qsize) [ seqno0 .. buffend0 ])
110 let nums = map fst . filter (isNothing . snd) $ zip [buffend0 ..] maybes
111 return nums
112
113-- | If seqno < buffend then return expected packet numbers for all
114-- the Nothings in the array between them.
102-- Otherwise, behave as 'dequeue' would. 115-- Otherwise, behave as 'dequeue' would.
116-- TODO: Do we need this function? Delete it if not.
103dequeueOrGetMissing :: PacketQueue a -> STM (Either [Word32] a) 117dequeueOrGetMissing :: PacketQueue a -> STM (Either [Word32] a)
104dequeueOrGetMissing PacketQueue { pktq, seqno, qsize, buffend } = do 118dequeueOrGetMissing PacketQueue { pktq, seqno, qsize, buffend } = do
105 seqno0 <- readTVar seqno 119 seqno0 <- readTVar seqno
106 buffend0 <- readTVar buffend 120 buffend0 <- readTVar buffend
107 if seqno0 < buffend0 121 if seqno0 < buffend0
108 then do 122 then do
109 maybes <- mapM (readArray pktq) (take (fromIntegral qsize) $ map (`mod` qsize) [ buffend0 .. seqno0 ]) 123 maybes <- mapM (readArray pktq) (take (fromIntegral qsize) $ map (`mod` qsize) [ seqno0 .. buffend0 ])
110 let nums = map fst . filter (isNothing . snd) $ zip [buffend0 ..] maybes 124 let nums = map fst . filter (isNothing . snd) $ zip [buffend0 ..] maybes
111 return (Left nums) 125 return (Left nums)
112 else do 126 else do