diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-12 05:03:03 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-02 00:21:52 -0400 |
commit | ffaea2b2169a499aaa2ac72531beeb991714025a (patch) | |
tree | aaef07eb1ea57fd3cbdb885716955c1c9801da67 /src/Network/Lossless.hs | |
parent | 49dd57c58d9e9d5d31c35c8960686512703e0bae (diff) |
Lossless: Support for handling exceptions on send.
Diffstat (limited to 'src/Network/Lossless.hs')
-rw-r--r-- | src/Network/Lossless.hs | 21 |
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 | |||
14 | import Control.Monad.STM | 14 | import Control.Monad.STM |
15 | import Data.Function | 15 | import Data.Function |
16 | import Data.Word | 16 | import Data.Word |
17 | import System.IO.Error | ||
17 | 18 | ||
18 | import Data.PacketBuffer as PB | 19 | import Data.PacketBuffer as PB |
19 | import DPut | 20 | import DPut |
@@ -32,12 +33,19 @@ data SequenceInfo = SequenceInfo | |||
32 | } | 33 | } |
33 | deriving (Eq,Ord,Show) | 34 | deriving (Eq,Ord,Show) |
34 | 35 | ||
36 | data 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. |
36 | lossless :: Show addr => | 43 | lossless :: 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 |