@@ -16,7 +16,6 @@ import Foreign.Ptr (minusPtr, plusPtr)
1616import Network.ByteOrder
1717import Network.HTTP.Semantics.Client
1818import Network.HTTP.Semantics.IO
19- import System.ThreadManager
2019
2120import Imports
2221import Network.HPACK (setLimitForEncoding , toTokenHeaderTable )
@@ -59,38 +58,42 @@ updatePeerSettings Context{peerSettings, oddStreamTable, evenStreamTable} peerAl
5958 updateAllStreamTxFlow siz strms =
6059 forM_ strms $ \ strm -> increaseStreamWindowSize strm siz
6160
62- checkDone :: Context -> Int -> IO Bool
61+ checkDone :: Context -> Int -> IO ( Maybe E. SomeException )
6362checkDone Context {.. } 0 = atomically $ do
6463 isEmptyC <- isEmptyTQueue controlQ
6564 isEmptyO <- isEmptyTQueue outputQ
6665 if not isEmptyC || not isEmptyO
6766 then
68- return False
67+ return Nothing
6968 else do
70- gone <- isAllGone threadManager
71- unless gone retry
72- done <- readTVar receiverDone
73- unless done retry
74- return True
75- checkDone _ _ = return False
69+ recv <- readTVar receiverDone
70+ case recv of
71+ Just done ->
72+ return $ Just done
73+ _otherwise ->
74+ retry
75+ checkDone _ _ = return Nothing
7676
77- frameSender :: Context -> Config -> IO ()
77+ frameSender :: Context -> Config -> IO E. SomeException
7878frameSender
7979 ctx@ Context {outputQ, controlQ, encodeDynamicTable, outputBufferLimit}
8080 Config {.. } = do
8181 labelMe " H2 sender"
82- loop 0
82+ loop 0 `E.catch` return
8383 where
8484 ----------------------------------------------------------------
85- loop :: Offset -> IO ()
85+ loop :: Offset -> IO E. SomeException
8686 loop off = do
87- done <- checkDone ctx off
88- unless done $ do
89- x <- atomically $ dequeue off
90- case x of
91- C ctl -> flushN off >> control ctl >> loop 0
92- O out -> outputAndSync out off >>= flushIfNecessary >>= loop
93- Flush -> flushN off >> loop 0
87+ mDone <- checkDone ctx off
88+ case mDone of
89+ Just done ->
90+ return done
91+ Nothing -> do
92+ x <- atomically $ dequeue off
93+ case x of
94+ C ctl -> flushN off >> control ctl >> loop 0
95+ O out -> outputAndSync out off >>= flushIfNecessary >>= loop
96+ Flush -> flushN off >> loop 0
9497
9598 -- Flush the connection buffer to the socket, where the first 'n' bytes of
9699 -- the buffer are filled.
0 commit comments