diff options
author | jim@bo <jim@bo> | 2018-06-21 04:43:44 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-21 04:43:44 -0400 |
commit | 32c87f6b6b632ac3a13bc504d80bedc7e6a52bdd (patch) | |
tree | dfee221e7d8ee376f52d66aa675df55ef3d57369 /src/Data | |
parent | a33fd34516e405d29654dff85df235b3c26ab565 (diff) |
netCrypto packet-request thread wip (continued)
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/PacketQueue.hs | 16 |
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. | ||
104 | getMissing :: PacketQueue a -> STM [Word32] | ||
105 | getMissing 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. | ||
103 | dequeueOrGetMissing :: PacketQueue a -> STM (Either [Word32] a) | 117 | dequeueOrGetMissing :: PacketQueue a -> STM (Either [Word32] a) |
104 | dequeueOrGetMissing PacketQueue { pktq, seqno, qsize, buffend } = do | 118 | dequeueOrGetMissing 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 |