[Haskell-cafe] hSetBuffering woes

Eric eeoam at ukfsn.org
Sat Jun 16 15:14:26 EDT 2007

Bryan O'Sullivan wrote:
> Eric wrote:
>> I tried to turn off buffering with the command hSetBuffering (from 
>> System.IO) but my app still blocks on hGetContents (from 
>> Data.ByteString). Does anyone know what's happening?
> The hGetContents function can't behave the way you want, because it's 
> defined to return the entire rest of the input stream.
> If you want to stick with strict ByteStrings, use hGetNonBlocking 
> instead, but you'll need to block between reads of the handle 
> yourself, using System.IO.hWaitForInput.
> Otherwise, use lazy ByteStrings.  That version of hGetContents will 
> lazily yield chunks that are as big as can be read without blocking as 
> they arrive (up to a limit of 64KB), and will hWaitForInput for you.
>     <b

I've converted to lazy bytestrings. After reading in the bytes from a 
network connection I want to save them to a file but now the appendFile 
function blocks:

import Data.ByteString.Lazy as LazyBits(ByteString, empty, hGetContents, 
writeFile, appendFile)
LazyBits.appendFile filepath bits         -- this blocks now!

How can I fix this?


More information about the Haskell-Cafe mailing list