on master help sign in
Defining enqueueOrSpawnTemporaryWaiter (#423).
commitc6bac47419c6f4375d4c24623e5868741002eafc authorKazu Yamamoto <kazu@iij.ad.jp> dateThu 13 Aug 2015, 09:46 (11 years ago) parent472b767
3 files changed+13−13
warp/Network/Wai/Handler/Warp/HTTP2/Sender.hs+1−7 warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+11 warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+1−6
warp/Network/Wai/Handler/Warp/HTTP2/Sender.hs+1−7
@@ -7,7 +7,6 @@ module Network.Wai.Handler.Warp.HTTP2.Sender (frameSender) where
77#if __GLASGOW_HASKELL__ < 709
88import Control.Applicative
99#endif
10−import Control.Concurrent (forkIO)
1110import Control.Concurrent.STM
1211import qualified Control.Exception as E
1312import Control.Monad (unless, void, when)
@@ -182,12 +181,7 @@ frameSender ctx@Context{outputQ,connectionWindow}
182181 maybeEnqueueNext :: Stream -> Control DynaNext -> IO ()
183182 maybeEnqueueNext strm (CNext next) = do
184183 let out = ONext strm next
185− sw <- atomically $ readTVar $ streamWindow strm
186− if sw == 0 then
187− void $ forkIO $ enqueueWhenWindowIsOpen outputQ out
188− else do
189− pri <- readIORef $ streamPriority strm
190− enqueue outputQ out pri
184+ enqueueOrSpawnTemporaryWaiter strm outputQ out
191185 -- If the streaming is not finished, it must already have been
192186 -- written to the 'TVar' owned by 'waiter', which will
193187 -- put it back into the queue when more output becomes available.
warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+11
@@ -7,6 +7,7 @@ import Data.ByteString.Builder (Builder)
77#if __GLASGOW_HASKELL__ < 709
88import Control.Applicative ((<$>),(<*>))
99#endif
10+import Control.Concurrent (forkIO)
1011import Control.Concurrent.STM
1112import Control.Exception (SomeException)
1213import Control.Monad (void)
@@ -245,3 +246,13 @@ enqueueWhenWindowIsOpen outQ out = do
245246 check (x > 0)
246247 pri <- readIORef $ streamPriority strm
247248 enqueue outQ out pri
249+
250+enqueueOrSpawnTemporaryWaiter :: Stream -> PriorityTree Output -> Output -> IO ()
251+enqueueOrSpawnTemporaryWaiter strm outQ out = do
252+ sw <- atomically $ readTVar $ streamWindow strm
253+ if sw == 0 then
254+ -- This waiter waits only for the stream window.
255+ void $ forkIO $ enqueueWhenWindowIsOpen outQ out
256+ else do
257+ pri <- readIORef $ streamPriority strm
258+ enqueue outQ out pri
warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+1−6
@@ -76,12 +76,7 @@ response Context{outputQ} mgr tconf th strm req rsp = do
7676 let hasBody = requestMethod req /= H.methodHead
7777 && R.hasBody (responseStatus rsp)
7878 out = OResponse strm rsp (Oneshot hasBody)
79− sw <- atomically $ readTVar $ streamWindow strm
80− if sw == 0 then
81− void $ forkIO $ enqueueWhenWindowIsOpen outputQ out
82− else do
83− pri <- readIORef $ streamPriority strm
84− enqueue outputQ out pri
79+ enqueueOrSpawnTemporaryWaiter strm outputQ out
8580 return ResponseReceived
8681
8782data Break = Break deriving (Show, Typeable)