[Haskell-cafe] hSetBuffering woes

Bryan O'Sullivan bos at serpentine.com
Sat Jun 16 14:17:22 EDT 2007

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.


More information about the Haskell-Cafe mailing list