summaryrefslogtreecommitdiff
path: root/src/Data/PacketQueue.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-11-21 20:52:45 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-11-21 20:52:45 +0000
commit3df9ab5c2ee9c0b09658fb0bc052f413b82f0fd3 (patch)
tree5a805a2686bc838a3ab863f5e36d0ac9188e8dbd /src/Data/PacketQueue.hs
parent2ff856624c60b6399407ad0dbc8a68ba2dcffab5 (diff)
Outgoing Sink & overwrite old packets in PacketOutQueue
Diffstat (limited to 'src/Data/PacketQueue.hs')
-rw-r--r--src/Data/PacketQueue.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Data/PacketQueue.hs b/src/Data/PacketQueue.hs
index cde26fb7..b7737656 100644
--- a/src/Data/PacketQueue.hs
+++ b/src/Data/PacketQueue.hs
@@ -12,8 +12,10 @@ module Data.PacketQueue
12 , observeOutOfBand 12 , observeOutOfBand
13 , PacketOutQueue 13 , PacketOutQueue
14 , newOutGoing 14 , newOutGoing
15 , readyOutGoing
15 , tryAppendQueueOutgoing 16 , tryAppendQueueOutgoing
16 , dequeueOutgoing 17 , dequeueOutgoing
18 , getHighestHandledPacketPlus1
17 , mapOutGoing 19 , mapOutGoing
18 , OutGoingResult(..) 20 , OutGoingResult(..)
19 ) where 21 ) where
@@ -158,8 +160,18 @@ tryAppendQueueOutgoing getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPac
158 writeTVar pktoPacketNo $! pktno' 160 writeTVar pktoPacketNo $! pktno'
159 writeArray (pktq pktoOutPQ) i (Just (pktno,pkt)) 161 writeArray (pktq pktoOutPQ) i (Just (pktno,pkt))
160 return OGSuccess 162 return OGSuccess
161 -- queue is full, block until its not 163 -- queue is full
162 _ -> return OGFull 164 Just (n,_) -> do
165 nn <- getHighestHandledPacketPlus1 q
166 if (n < nn)
167 -- but we can overwrite an old packet
168 then do
169 modifyTVar' (buffend pktoOutPQ) (+1)
170 writeTVar pktoPacketNo $! pktno'
171 writeArray (pktq pktoOutPQ) i (Just (pktno,pkt))
172 return OGSuccess
173 -- uh oh this packet is still needed...
174 else return OGFull
163 -- don't know how to send this message 175 -- don't know how to send this message
164 Nothing -> return OGEncodeFail 176 Nothing -> return OGEncodeFail
165 177
@@ -172,3 +184,5 @@ dequeueOutgoing (PacketOutQueue {pktoOutPQ=PacketQueue { pktq, seqno, qsize }})
172 modifyTVar' seqno succ 184 modifyTVar' seqno succ
173 return x 185 return x
174 186
187getHighestHandledPacketPlus1 :: PacketOutQueue extra msg wire fromwire -> STM Word32
188getHighestHandledPacketPlus1 (PacketOutQueue { pktoInPQ }) = readTVar (buffend pktoInPQ)