diff options
-rw-r--r-- | libraries/base/GHC/IO/Buffer.hs | 2 | ||||
-rw-r--r-- | libraries/base/GHC/IO/Handle/Text.hs | 15 |
2 files changed, 12 insertions, 5 deletions
diff --git a/libraries/base/GHC/IO/Buffer.hs b/libraries/base/GHC/IO/Buffer.hs index f169ae6f5f..844818357f 100644 --- a/libraries/base/GHC/IO/Buffer.hs +++ b/libraries/base/GHC/IO/Buffer.hs @@ -202,7 +202,7 @@ data Buffer e bufRaw :: !(RawBuffer e), bufState :: BufferState, bufSize :: !Int, -- in elements, not bytes - bufOffset :: !Word64, -- start location for next read + bufOffset :: !Word64, -- start location for next read/write bufL :: !Int, -- offset of first item in the buffer bufR :: !Int -- offset of last item + 1 } diff --git a/libraries/base/GHC/IO/Handle/Text.hs b/libraries/base/GHC/IO/Handle/Text.hs index a934af0007..64559e30df 100644 --- a/libraries/base/GHC/IO/Handle/Text.hs +++ b/libraries/base/GHC/IO/Handle/Text.hs @@ -857,10 +857,17 @@ bufWrite h_@Handle__{..} ptr count can_block = -- if we can fit in the buffer, then just loop if count < size then bufWrite h_ ptr count can_block - else if can_block - then do writeChunk h_ (castPtr ptr) offset count - return count - else writeChunkNonBlocking h_ (castPtr ptr) offset count + else do + !bytes <- if can_block + then do writeChunk h_ (castPtr ptr) offset count + return count + else writeChunkNonBlocking h_ (castPtr ptr) offset count + -- Even if we bypass the buffer we must update the offset for the buffer + -- for future writes. + !buf <- readIORef haByteBuffer + writeIORef haByteBuffer $! bufferAddOffset bytes buf + return bytes + writeChunk :: Handle__ -> Ptr Word8 -> Word64 -> Int -> IO () writeChunk h_@Handle__{..} ptr offset bytes |