From 3efe74f3acd0dff20d078b6e8416664193b219d4 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 16 Sep 2010 11:37:32 +0000 Subject: [PATCH] some fixes for hGetBufSome - fix one case where it was blocking when it shouldn't - a couple of error-message tweaks --- GHC/IO/Handle/Text.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GHC/IO/Handle/Text.hs b/GHC/IO/Handle/Text.hs index 745dc18..ebb29c8 100644 --- a/GHC/IO/Handle/Text.hs +++ b/GHC/IO/Handle/Text.hs @@ -891,9 +891,9 @@ bufReadEmpty h_@Handle__{..} hGetBufSome :: Handle -> Ptr a -> Int -> IO Int hGetBufSome h ptr count | count == 0 = return 0 - | count < 0 = illegalBufferSize h "hGetBuf" count + | count < 0 = illegalBufferSize h "hGetBufSome" count | otherwise = - wantReadableHandle_ "hGetBuf" h $ \ h_@Handle__{..} -> do + wantReadableHandle_ "hGetBufSome" h $ \ h_@Handle__{..} -> do flushCharReadBuffer h_ buf@Buffer{ bufSize=sz } <- readIORef haByteBuffer if isEmptyBuffer buf @@ -903,7 +903,10 @@ hGetBufSome h ptr count if r == 0 then return 0 else do writeIORef haByteBuffer buf' - bufReadNBNonEmpty h_ buf' (castPtr ptr) 0 count + bufReadNBNonEmpty h_ buf' (castPtr ptr) 0 (min r count) + -- new count is (min r count), so + -- that bufReadNBNonEmpty will not + -- issue another read. else bufReadNBEmpty h_ buf (castPtr ptr) 0 count -- 1.7.10.4