Potential Network SIG
Duncan Coutts
duncan.coutts at worc.ox.ac.uk
Fri Sep 11 07:53:07 EDT 2009
On Thu, 2009-09-10 at 16:05 +0100, Ian Lynagh wrote:
> On Wed, Aug 26, 2009 at 05:42:19PM +0100, Simon Marlow wrote:
> >>
> >> As far as buffering goes, Handles currently couple buffering modes, which is
> >> potentially frustrating if one wants, e.g., no buffering on recv, but block
> >> buffering on send.
> >
> > Buffering is always invisible on input - if there is any input
> > available, you'll see it immediately. It has performance implications
> > only - but I can't imagine you'd want to deliberately reduce performance
> > by turning off buffering (in fact, I think the new I/O library doesn't
> > even honour NoBuffering on input Handles).
>
> So is this program supposed to not be valid (or at least, to not behave
> as I would expect)?
>
> import Control.Monad
> import System.Environment
> import System.IO
> import System.Posix.Process
>
> main :: IO ()
> main = do [get] <- getArgs
> hSetBuffering stdin NoBuffering
> when (read get) $ do x <- hGetChar stdin
> putStrLn ("Got: " ++ show x)
> executeFile "cat" True [] Nothing
So you're accessing the stdin file descriptor via the stdin Handle and
also directly via cat. Note that there's no API in Haskell code to get
at the unadorned FD while keeping the Handle open.
Duncan
More information about the Libraries
mailing list