Raw I/O library proposal, second (more pragmatic) draft

Simon Marlow simonmar@microsoft.com
Fri, 8 Aug 2003 09:35:44 +0100


=20
> Here's the code for hFlush from the GHC 6.0 sources:
>=20
>  =20
> --------------------------------------------------------------
> -------------
>   -- hFlush
>=20
>   -- The action `hFlush hdl' causes any items buffered for output
>   -- in handle `hdl' to be sent immediately to the operating
>   -- system.
>=20
>   hFlush :: Handle -> IO ()
>   hFlush handle =3D
>      wantWritableHandle "hFlush" handle $ \ handle_ -> do
>      buf <- readIORef (haBuffer handle_)
>      if bufferIsWritable buf && not (bufferEmpty buf)
>           then do flushed_buf <- flushWriteBuffer (haFD handle_)
>                                                   (haIsStream=20
> handle_) buf
>                   writeIORef (haBuffer handle_) flushed_buf
>           else return ()

I stand corrected :-)

I was thinking about what happens when a read/write Handle with a full
read buffer is written to.  This is one of the really awkward cases in
the current IO library - you have to discard the input buffer, but also
move the file pointer back to where it should be before you start
writing.

Cheers,
	Simon