summaryrefslogtreecommitdiff
path: root/src/Data/PacketQueue.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-06-19 23:50:08 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-06-19 23:50:08 +0000
commit185d22daefbfb5a10789121baf6b4aaf35a7535b (patch)
treec2ee0a3c3ba46bdb350550e12cbb1029e541f9b0 /src/Data/PacketQueue.hs
parenta564eb632153b7e194c7b09fe646817d621c8f40 (diff)
cleanup code for netcrypto sessions
Diffstat (limited to 'src/Data/PacketQueue.hs')
-rw-r--r--src/Data/PacketQueue.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Data/PacketQueue.hs b/src/Data/PacketQueue.hs
index cb308bce..f9d9f28f 100644
--- a/src/Data/PacketQueue.hs
+++ b/src/Data/PacketQueue.hs
@@ -17,6 +17,7 @@ module Data.PacketQueue
17 , packetQueueViewList 17 , packetQueueViewList
18 , newOutGoing 18 , newOutGoing
19 , readyOutGoing 19 , readyOutGoing
20 , peekPacket
20 , tryAppendQueueOutgoing 21 , tryAppendQueueOutgoing
21 , dequeueOutgoing 22 , dequeueOutgoing
22 , getHighestHandledPacketPlus1 23 , getHighestHandledPacketPlus1
@@ -187,6 +188,27 @@ data OutGoingResult = OGSuccess | OGFull | OGEncodeFail
187readyOutGoing :: PacketOutQueue extra msg wire fromwire -> IO (STM extra) 188readyOutGoing :: PacketOutQueue extra msg wire fromwire -> IO (STM extra)
188readyOutGoing (PacketOutQueue {pktoToWireIO }) = pktoToWireIO 189readyOutGoing (PacketOutQueue {pktoToWireIO }) = pktoToWireIO
189 190
191peekPacket :: STM extra -> PacketOutQueue extra msg wire fromwire -> msg -> STM (Maybe (wire,Word32))
192peekPacket getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPacketNo, pktoToWireIO, pktoToWire }) msg
193 = do
194 be <- readTVar (buffend pktoOutPQ)
195 let i = be `mod` (qsize pktoOutPQ)
196 let arrayEmpty :: MArray a e m => a Word32 e -> m Bool
197 arrayEmpty ar = do (lowB,highB) <- getBounds ar
198 let result= lowB > highB
199 return $ trace ("arrayEmpty result=" ++ show result
200 ++ " lowB=" ++ show lowB
201 ++ " highB = " ++ show highB
202 ++ " i = " ++ show i) result
203 mbPkt <- do emp <- arrayEmpty (pktq pktoOutPQ)
204 if emp then trace "(peekPacket empty)" $ return Nothing
205 else trace "(peekPacket nonempty)" $ do
206 result <- readArray (pktq pktoOutPQ) i
207 return $ trace ("readArray (isJust result)==" ++ show (isJust result)) result
208 pktno <- readTVar pktoPacketNo
209 nextno <- readTVar (seqno pktoInPQ)
210 pktoToWire getExtra nextno be pktno msg
211
190-- | Convert a message to packet format and append it to the front of a queue 212-- | Convert a message to packet format and append it to the front of a queue
191-- used for outgoing messages. (Note that ‘front‛ usually means the higher 213-- used for outgoing messages. (Note that ‘front‛ usually means the higher
192-- index in this implementation.) 214-- index in this implementation.)
@@ -210,6 +232,7 @@ tryAppendQueueOutgoing getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPac
210 pktno <- readTVar pktoPacketNo 232 pktno <- readTVar pktoPacketNo
211 nextno <- readTVar (seqno pktoInPQ) 233 nextno <- readTVar (seqno pktoInPQ)
212 mbWire <- pktoToWire getExtra nextno be pktno msg 234 mbWire <- pktoToWire getExtra nextno be pktno msg
235 -- TODO all the above lines ^^ can be replaced with call to peekPacket
213 case trace "(tryAppendQueueOutgoing mbWire)" mbWire of 236 case trace "(tryAppendQueueOutgoing mbWire)" mbWire of
214 Just (pkt,pktno') 237 Just (pkt,pktno')
215 -> trace "(tryAppendQueueOutgoing A)" 238 -> trace "(tryAppendQueueOutgoing A)"