summaryrefslogtreecommitdiff
path: root/src/Network/Lossless.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-09-12 05:03:03 -0400
committerJoe Crayne <joe@jerkface.net>2018-11-02 00:21:52 -0400
commitffaea2b2169a499aaa2ac72531beeb991714025a (patch)
treeaaef07eb1ea57fd3cbdb885716955c1c9801da67 /src/Network/Lossless.hs
parent49dd57c58d9e9d5d31c35c8960686512703e0bae (diff)
Lossless: Support for handling exceptions on send.
Diffstat (limited to 'src/Network/Lossless.hs')
-rw-r--r--src/Network/Lossless.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Network/Lossless.hs b/src/Network/Lossless.hs
index ff0b8cc1..4d5521fd 100644
--- a/src/Network/Lossless.hs
+++ b/src/Network/Lossless.hs
@@ -14,6 +14,7 @@ import Control.Monad
14import Control.Monad.STM 14import Control.Monad.STM
15import Data.Function 15import Data.Function
16import Data.Word 16import Data.Word
17import System.IO.Error
17 18
18import Data.PacketBuffer as PB 19import Data.PacketBuffer as PB
19import DPut 20import DPut
@@ -32,12 +33,19 @@ data SequenceInfo = SequenceInfo
32 } 33 }
33 deriving (Eq,Ord,Show) 34 deriving (Eq,Ord,Show)
34 35
36data OutgoingInfo y = OutgoingInfo
37 { oIsLossy :: Bool -- ^ True if the packet is treated as lossy.
38 , oEncoded :: y -- ^ The packet.
39 , oHandleException :: Maybe (IOError -> IO ()) -- ^ Optionally handle send failure.
40 }
41
35-- | Obtain a reliable transport form an unreliable one. 42-- | Obtain a reliable transport form an unreliable one.
36lossless :: Show addr => 43lossless :: Show addr =>
37 (x -> addr -> IO (PacketInboundEvent (x',addr'))) -- ^ Used to classify newly arrived packets. 44 (x -> addr -> IO (PacketInboundEvent (x',addr'))) -- ^ Used to classify newly arrived packets.
38 -> (SequenceInfo -> x' -> addr' -> IO (Bool,y)) -- ^ Used to encode and classify outbound packets. 45 -> (SequenceInfo -> x' -> addr' -> IO (OutgoingInfo y)) -- ^ Used to encode and classify outbound packets.
39 -> addr -- ^ The remote address for this session. 46 -> addr -- ^ The remote address for this session.
40 -> TransportA String addr x y -- ^ An unreliable lossy transport. 47 -> TransportA String addr x y -- ^ An unreliable lossy transport.
48
41 -> IO ( Transport String addr' x' -- ^ A reliable lossless transport. 49 -> IO ( Transport String addr' x' -- ^ A reliable lossless transport.
42 , [Word32] -> IO () -- ^ Use this to request lost packets be re-sent. 50 , [Word32] -> IO () -- ^ Use this to request lost packets be re-sent.
43 , IO ([Word32],Word32) -- ^ Use this to discover missing packets to request. 51 , IO ([Word32],Word32) -- ^ Use this to discover missing packets to request.
@@ -86,7 +94,7 @@ lossless isLossless encode saddr udp = do
86 seqno <- PB.nextToSendSequenceNumber pb 94 seqno <- PB.nextToSendSequenceNumber pb
87 ack <- PB.expectingSequenceNumber pb 95 ack <- PB.expectingSequenceNumber pb
88 return $ SequenceInfo seqno ack 96 return $ SequenceInfo seqno ack
89 (islossy,x) <- encode seqno x' a' 97 OutgoingInfo islossy x oops <- encode seqno x' a'
90 (isfull,nn) <- 98 (isfull,nn) <-
91 if islossy 99 if islossy
92 then do 100 then do
@@ -100,7 +108,8 @@ lossless isLossless encode saddr udp = do
100 atomically $ do 108 atomically $ do
101 (isfull,_) <- PB.grokOutboundPacket pb (PacketSent (sequenceNumber seqno) x) 109 (isfull,_) <- PB.grokOutboundPacket pb (PacketSent (sequenceNumber seqno) x)
102 when isfull retry 110 when isfull retry
103 sendMessage udp saddr x 111 let sendit = sendMessage udp saddr x
112 maybe sendit (catchIOError sendit) oops
104 , closeTransport = do 113 , closeTransport = do
105 atomically $ writeTChan oob Nothing -- quit rloop thread 114 atomically $ writeTChan oob Nothing -- quit rloop thread
106 closeTransport udp 115 closeTransport udp