- = if count > sz -- large read?
- then do rest <- readChunkNonBlocking h_ ptr count
- return (so_far + rest)
- else do (r,buf') <- Buffered.fillReadBuffer0 haDevice buf
- case r of
- Nothing -> return so_far
- Just 0 -> return so_far
- Just r -> do
- writeIORef haByteBuffer buf'
- bufReadNBNonEmpty h_ buf' ptr so_far (min count r)
- -- NOTE: new count is min count w'
+ | count > sz, False,
+ Just fd <- cast haDevice = do
+ m <- RawIO.readNonBlocking (fd::FD) ptr count
+ case m of
+ Nothing -> return so_far
+ Just n -> return (so_far + n)
+
+ | otherwise = do
+ buf <- readIORef haByteBuffer
+ (r,buf') <- Buffered.fillReadBuffer0 haDevice buf
+ case r of
+ Nothing -> return so_far
+ Just 0 -> return so_far
+ Just r -> do
+ writeIORef haByteBuffer buf'
+ bufReadNBNonEmpty h_ buf' ptr so_far (min count r)
+ -- NOTE: new count is min count r