Ensure hGetBufSome does not cause potentially blocking reads (#5843)
authorPaolo Capriotti <p.capriotti@gmail.com>
Tue, 27 Mar 2012 15:37:06 +0000 (16:37 +0100)
committerPaolo Capriotti <p.capriotti@gmail.com>
Tue, 27 Mar 2012 16:37:33 +0000 (17:37 +0100)
When there is data in a handle buffer, never fetch more than the
available number of elements, since that can cause a blocking read on
Windows.

GHC/IO/Handle/Text.hs

index 280cebd..3eedae6 100644 (file)
@@ -889,7 +889,8 @@ hGetBufSome h ptr count
                                         -- that bufReadNBNonEmpty will not
                                         -- issue another read.
             else
-              bufReadNBNonEmpty h_ buf (castPtr ptr) 0 count
+              let count' = min count (bufferElems buf)
+              in bufReadNBNonEmpty h_ buf (castPtr ptr) 0 count'
 
 haFD :: Handle__ -> FD
 haFD h_@Handle__{..} =