diff options
author | jim@bo <jim@bo> | 2018-06-21 17:02:47 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-21 17:02:47 -0400 |
commit | 217823867e3874cb4d3d8d619bc192aaf6c78028 (patch) | |
tree | a4225fa927137961ccae4a0e824f5aaf5a361814 /src/Data | |
parent | f0f2bd11e0fc53ee0442dd110ff0a297716f1eda (diff) |
DPut Trace Variations
tput - like dput, but works in any Applicative
dtrace - like trace, but takes DebugTag
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/PacketQueue.hs | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/Data/PacketQueue.hs b/src/Data/PacketQueue.hs index e0221f5a..8182706e 100644 --- a/src/Data/PacketQueue.hs +++ b/src/Data/PacketQueue.hs | |||
@@ -35,7 +35,7 @@ import Control.Applicative | |||
35 | import Data.Word | 35 | import Data.Word |
36 | import Data.Array.MArray | 36 | import Data.Array.MArray |
37 | import Data.Maybe | 37 | import Data.Maybe |
38 | import Debug.Trace | 38 | import DPut |
39 | 39 | ||
40 | data PacketQueue a = PacketQueue | 40 | data PacketQueue a = PacketQueue |
41 | { pktq :: TArray Word32 (Maybe a) | 41 | { pktq :: TArray Word32 (Maybe a) |
@@ -234,15 +234,18 @@ peekPacket getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPacketNo, pktoT | |||
234 | let arrayEmpty :: MArray a e m => a Word32 e -> m Bool | 234 | let arrayEmpty :: MArray a e m => a Word32 e -> m Bool |
235 | arrayEmpty ar = do (lowB,highB) <- getBounds ar | 235 | arrayEmpty ar = do (lowB,highB) <- getBounds ar |
236 | let result= lowB > highB | 236 | let result= lowB > highB |
237 | return $ trace ("arrayEmpty result=" ++ show result | 237 | tput XNetCrypto |
238 | ("arrayEmpty result=" ++ show result | ||
238 | ++ " lowB=" ++ show lowB | 239 | ++ " lowB=" ++ show lowB |
239 | ++ " highB = " ++ show highB | 240 | ++ " highB = " ++ show highB |
240 | ++ " i = " ++ show i) result | 241 | ++ " i = " ++ show i) |
242 | return result | ||
241 | mbPkt <- do emp <- arrayEmpty (pktq pktoOutPQ) | 243 | mbPkt <- do emp <- arrayEmpty (pktq pktoOutPQ) |
242 | if emp then trace "(peekPacket empty)" $ return Nothing | 244 | if emp then tput XNetCrypto "(peekPacket empty)" >> return Nothing |
243 | else trace "(peekPacket nonempty)" $ do | 245 | else do tput XNetCrypto "(peekPacket nonempty)" |
244 | result <- readArray (pktq pktoOutPQ) i | 246 | result <- readArray (pktq pktoOutPQ) i |
245 | return $ trace ("readArray (isJust result)==" ++ show (isJust result)) result | 247 | tput XNetCrypto ("readArray (isJust result)==" ++ show (isJust result)) |
248 | return result | ||
246 | pktno <- readTVar pktoPacketNo | 249 | pktno <- readTVar pktoPacketNo |
247 | nextno <- readTVar (seqno pktoInPQ) | 250 | nextno <- readTVar (seqno pktoInPQ) |
248 | pktoToWire getExtra nextno be pktno msg | 251 | pktoToWire getExtra nextno be pktno msg |
@@ -252,37 +255,40 @@ peekPacket getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPacketNo, pktoT | |||
252 | -- index in this implementation.) | 255 | -- index in this implementation.) |
253 | tryAppendQueueOutgoing :: STM extra -> PacketOutQueue extra msg wire fromwire -> msg -> STM OutGoingResult | 256 | tryAppendQueueOutgoing :: STM extra -> PacketOutQueue extra msg wire fromwire -> msg -> STM OutGoingResult |
254 | tryAppendQueueOutgoing getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPacketNo, pktoToWireIO, pktoToWire }) msg | 257 | tryAppendQueueOutgoing getExtra q@(PacketOutQueue { pktoInPQ, pktoOutPQ, pktoPacketNo, pktoToWireIO, pktoToWire }) msg |
255 | = trace "(tryAppendQueueOutgoing)" $ do | 258 | = dtrace XNetCrypto "(tryAppendQueueOutgoing)" $ do |
256 | be <- readTVar (buffend pktoOutPQ) | 259 | be <- readTVar (buffend pktoOutPQ) |
257 | let i = be `mod` (qsize pktoOutPQ) | 260 | let i = be `mod` (qsize pktoOutPQ) |
258 | let arrayEmpty :: MArray a e m => a Word32 e -> m Bool | 261 | let arrayEmpty :: MArray a e m => a Word32 e -> m Bool |
259 | arrayEmpty ar = do (lowB,highB) <- getBounds ar | 262 | arrayEmpty ar = do (lowB,highB) <- getBounds ar |
260 | let result= lowB > highB | 263 | let result= lowB > highB |
261 | return $ trace ("arrayEmpty result=" ++ show result | 264 | tput XNetCrypto |
265 | ("arrayEmpty result=" ++ show result | ||
262 | ++ " lowB=" ++ show lowB | 266 | ++ " lowB=" ++ show lowB |
263 | ++ " highB = " ++ show highB | 267 | ++ " highB = " ++ show highB |
264 | ++ " i = " ++ show i) result | 268 | ++ " i = " ++ show i) |
269 | return result | ||
265 | mbPkt <- do emp <- arrayEmpty (pktq pktoOutPQ) | 270 | mbPkt <- do emp <- arrayEmpty (pktq pktoOutPQ) |
266 | if emp then trace "(tryAppendQueueOutgoing empty)" $ return Nothing | 271 | if emp then tput XNetCrypto "(tryAppendQueueOutgoing empty)" >> return Nothing |
267 | else trace "(tryAppendQueueOutgoing nonempty)" $ do | 272 | else do tput XNetCrypto "(tryAppendQueueOutgoing nonempty)" |
268 | result <- readArray (pktq pktoOutPQ) i | 273 | result <- readArray (pktq pktoOutPQ) i |
269 | return $ trace ("readArray (isJust result)==" ++ show (isJust result)) result | 274 | tput XNetCrypto ("readArray (isJust result)==" ++ show (isJust result)) |
275 | return result | ||
270 | pktno <- readTVar pktoPacketNo | 276 | pktno <- readTVar pktoPacketNo |
271 | nextno <- readTVar (seqno pktoInPQ) | 277 | nextno <- readTVar (seqno pktoInPQ) |
272 | mbWire <- pktoToWire getExtra nextno be pktno msg | 278 | mbWire <- pktoToWire getExtra nextno be pktno msg |
273 | -- TODO all the above lines ^^ can be replaced with call to peekPacket | 279 | -- TODO all the above lines ^^ can be replaced with call to peekPacket |
274 | case trace "(tryAppendQueueOutgoing mbWire)" mbWire of | 280 | case dtrace XNetCrypto "(tryAppendQueueOutgoing mbWire)" mbWire of |
275 | Just (pkt,pktno') | 281 | Just (pkt,pktno') |
276 | -> trace "(tryAppendQueueOutgoing A)" | 282 | -> dtrace XNetCrypto "(tryAppendQueueOutgoing A)" |
277 | $ case mbPkt of | 283 | $ case mbPkt of |
278 | -- slot is free, insert element | 284 | -- slot is free, insert element |
279 | Nothing -> trace "(tryAppendQueueOutgoing Nothing case)" $ do | 285 | Nothing -> dtrace XNetCrypto "(tryAppendQueueOutgoing Nothing case)" $ do |
280 | modifyTVar' (buffend pktoOutPQ) (+1) | 286 | modifyTVar' (buffend pktoOutPQ) (+1) |
281 | writeTVar pktoPacketNo $! pktno' | 287 | writeTVar pktoPacketNo $! pktno' |
282 | writeArray (pktq pktoOutPQ) i (Just (pktno,pkt)) | 288 | writeArray (pktq pktoOutPQ) i (Just (pktno,pkt)) |
283 | return OGSuccess | 289 | return OGSuccess |
284 | -- queue is full | 290 | -- queue is full |
285 | Just (n,_) -> trace "tryAppendQueueOutgoing Just case)" $ do | 291 | Just (n,_) -> dtrace XNetCrypto "tryAppendQueueOutgoing Just case)" $ do |
286 | nn <- getHighestHandledPacketPlus1 q | 292 | nn <- getHighestHandledPacketPlus1 q |
287 | if (n < nn) | 293 | if (n < nn) |
288 | -- but we can overwrite an old packet | 294 | -- but we can overwrite an old packet |