diff options
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/PacketQueue.hs | 23 |
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 | |||
187 | readyOutGoing :: PacketOutQueue extra msg wire fromwire -> IO (STM extra) | 188 | readyOutGoing :: PacketOutQueue extra msg wire fromwire -> IO (STM extra) |
188 | readyOutGoing (PacketOutQueue {pktoToWireIO }) = pktoToWireIO | 189 | readyOutGoing (PacketOutQueue {pktoToWireIO }) = pktoToWireIO |
189 | 190 | ||
191 | peekPacket :: STM extra -> PacketOutQueue extra msg wire fromwire -> msg -> STM (Maybe (wire,Word32)) | ||
192 | peekPacket 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)" |