From 397d4e0f04fa71398a3582e0181617fbb1a0ac60 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Thu, 16 Jun 2016 14:53:08 +0900 Subject: [PATCH] refactoring for max concurrency. --- warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs | 9 +++++++-- warp/Network/Wai/Handler/Warp/HTTP2/Types.hs | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs b/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs index 343c58aa..769cd535 100644 --- a/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs +++ b/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs @@ -160,7 +160,8 @@ frameReceiver ctx mkreq recvN = loop 0 `E.catch` sendGoaway when (ftyp == FrameHeaders) $ do writeIORef currentStreamId streamId cnt <- readIORef concurrency - when (cnt >= recommendedConcurrency) $ + -- Checking the limitation of concurrency + when (cnt >= maxConcurrency) $ E.throwIO $ StreamError RefusedStream streamId ws <- initialWindowSize <$> readIORef http2settings newstrm <- newStream streamId (fromIntegral ws) @@ -170,8 +171,11 @@ frameReceiver ctx mkreq recvN = loop 0 `E.catch` sendGoaway consume = void . recvN +maxConcurrency :: Int +maxConcurrency = recommendedConcurrency + initialFrame :: ByteString -initialFrame = settingsFrame id [(SettingsMaxConcurrentStreams,recommendedConcurrency)] +initialFrame = settingsFrame id [(SettingsMaxConcurrentStreams,maxConcurrency)] ---------------------------------------------------------------- @@ -181,6 +185,7 @@ control FrameSettings header@FrameHeader{flags} bs Context{http2settings, contro case checkSettingsList alist of Just x -> E.throwIO x Nothing -> return () + -- HTTP/2 Setting from a browser unless (testAck flags) $ do modifyIORef' http2settings $ \old -> updateSettings old alist let !frame = settingsFrame setAck [] diff --git a/warp/Network/Wai/Handler/Warp/HTTP2/Types.hs b/warp/Network/Wai/Handler/Warp/HTTP2/Types.hs index 38a4df5f..72f4fd55 100644 --- a/warp/Network/Wai/Handler/Warp/HTTP2/Types.hs +++ b/warp/Network/Wai/Handler/Warp/HTTP2/Types.hs @@ -96,6 +96,7 @@ data Sequence = SFinish -- | The context for HTTP/2 connection. data Context = Context { + -- HTTP/2 settings received from a browser http2settings :: !(IORef Settings) , firstSettings :: !(IORef Bool) , streamTable :: !StreamTable