@@ -2,13 +2,13 @@
22{-# LANGUAGE RecordWildCards, NamedFieldPuns #-}
33{-# LANGUAGE BangPatterns #-}
44{-# LANGUAGE CPP #-}
5+{-# LANGUAGE PatternGuards #-}
56
67module Network.Wai.Handler.Warp.HTTP2.Receiver (frameReceiver) where
78
89#if __GLASGOW_HASKELL__ < 709
910import Control.Applicative
1011#endif
11−import Control.Concurrent (takeMVar)
1212import Control.Concurrent.STM
1313import qualified Control.Exception as E
1414import Control.Monad (when, unless, void)
@@ -27,8 +27,7 @@ import Network.Wai.Handler.Warp.Types
2727----------------------------------------------------------------
2828
2929frameReceiver :: Context -> MkReq -> (BufSize -> IO ByteString) -> IO ()
30−frameReceiver ctx mkreq recvN =
31− E.handle sendGoaway loop `E.finally` takeMVar wait
30+frameReceiver ctx mkreq recvN = loop `E.catch` sendGoaway
3231 where
3332 Context{ http2settings
3433 , streamTable
@@ -37,12 +36,13 @@ frameReceiver ctx mkreq recvN =
3736 , currentStreamId
3837 , inputQ
3938 , outputQ
40− , wait} = ctx
41− sendGoaway (ConnectionError err msg) = do
42− csid <- readIORef currentStreamId
43− let frame = goawayFrame csid err msg
44− enqueue outputQ (OGoaway frame) highestPriority
45− sendGoaway _ = return ()
39+ } = ctx
40+ sendGoaway e
41+ | Just (ConnectionError err msg) <- E.fromException e = do
42+ csid <- readIORef currentStreamId
43+ let frame = goawayFrame csid err msg
44+ enqueue outputQ (OGoaway frame) highestPriority
45+ | otherwise = return ()
4646
4747 sendReset err sid = do
4848 let frame = resetFrame err sid