Skip to content

Commit

Permalink
Merge PR yesodweb#946
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Oct 13, 2023
2 parents aefdd25 + a2de346 commit fa4bb2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions warp/Network/Wai/Handler/Warp/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import Network.Wai.Handler.Warp.Buffer
import Network.Wai.Handler.Warp.Imports
import Network.Wai.Handler.Warp.Types

toBufIOWith :: Int -> IORef WriteBuffer -> (ByteString -> IO ()) -> Builder -> IO ()
toBufIOWith :: Int -> IORef WriteBuffer -> (ByteString -> IO ()) -> Builder -> IO Int
toBufIOWith maxRspBufSize writeBufferRef io builder = do
writeBuffer <- readIORef writeBufferRef
loop writeBuffer firstWriter
loop writeBuffer firstWriter 0
where
firstWriter = runBuilder builder
loop writeBuffer writer = do
loop writeBuffer writer bytesSent = do
let buf = bufBuffer writeBuffer
size = bufSize writeBuffer
(len, signal) <- writer buf size
bufferIO buf len io
let totalBytesSent = len + bytesSent
case signal of
Done -> return ()
Done -> return totalBytesSent
More minSize next
| size < minSize -> do
when (minSize > maxRspBufSize) $
Expand All @@ -40,8 +41,8 @@ toBufIOWith maxRspBufSize writeBufferRef io builder = do
biggerWriteBuffer <- createWriteBuffer minSize
writeIORef writeBufferRef biggerWriteBuffer
return biggerWriteBuffer
loop biggerWriteBuffer next
| otherwise -> loop writeBuffer next
loop biggerWriteBuffer next totalBytesSent
| otherwise -> loop writeBuffer next totalBytesSent
Chunk bs next -> do
io bs
loop writeBuffer next
loop writeBuffer next totalBytesSent
4 changes: 2 additions & 2 deletions warp/Network/Wai/Handler/Warp/Response.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ sendRsp conn _ th ver s hs _ maxRspBufSize _ (RspBuilder body needsChunked) = do
<> chunkedTransferTerminator
| otherwise = header <> body
writeBufferRef = connWriteBuffer conn
toBufIOWith maxRspBufSize writeBufferRef (\bs -> connSendAll conn bs >> T.tickle th) hdrBdy
return (Just s, Nothing) -- fixme: can we tell the actual sent bytes?
len <- toBufIOWith maxRspBufSize writeBufferRef (\bs -> connSendAll conn bs >> T.tickle th) hdrBdy
return (Just s, Just $ fromIntegral len)

----------------------------------------------------------------

Expand Down

0 comments on commit fa4bb2a

Please sign in to comment.