Skip to content

Commit

Permalink
Merge PR #104
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Jan 16, 2024
2 parents 9e43f61 + b71c2c6 commit 0d78fb0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Network/HTTP2/H2/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,20 @@ setPeerStreamID ctx sid = writeIORef (peerStreamId ctx) sid

{-# INLINE setStreamState #-}
setStreamState :: Context -> Stream -> StreamState -> IO ()
setStreamState _ Stream{streamState} val = writeIORef streamState val
setStreamState _ Stream{streamState} newState = do
oldState <- readIORef streamState
case (oldState, newState) of
(Open _ (Body q _ _ _), Open _ (Body q' _ _ _)) | q == q' ->
-- The stream stays open with the same body; nothing to do
return ()
(Open _ (Body q _ _ _), _) ->
-- The stream is either closed, or is open with a /new/ body
-- We need to close the old queue so that any reads from it won't block
atomically $ writeTQueue q $ Left $ toException ConnectionIsClosed
_otherwise ->
-- The stream wasn't open to start with; nothing to do
return ()
writeIORef streamState newState

opened :: Context -> Stream -> IO ()
opened ctx strm = setStreamState ctx strm (Open Nothing JustOpened)
Expand Down

0 comments on commit 0d78fb0

Please sign in to comment.