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

Ben Rudiak-Gould benrg@dark.darkweb.com
Thu, 7 Aug 2003 09:28:31 -0700 (PDT)

On Thu, 7 Aug 2003, Simon Marlow wrote:

> It's not quite the same as calling streamGetAvailable.  flush would
> discard data that is buffered on the Haskell side, whereas
> streamGetAvailable might grab any data that is buffered in the OS.
> I'm not sure whether this is useful or not, but it's exactly what hFlush
> does currently.

Here's the code for hFlush from the GHC 6.0 sources:

  -- hFlush

  -- The action `hFlush hdl' causes any items buffered for output
  -- in handle `hdl' to be sent immediately to the operating
  -- system.

  hFlush :: Handle -> IO ()
  hFlush handle =
     wantWritableHandle "hFlush" handle $ \ handle_ -> do
     buf <- readIORef (haBuffer handle_)
     if bufferIsWritable buf && not (bufferEmpty buf)
          then do flushed_buf <- flushWriteBuffer (haFD handle_)
                                                  (haIsStream handle_) buf
                  writeIORef (haBuffer handle_) flushed_buf
          else return ()

I'm not sure what it does to input buffers, but it doesn't seem like it's
designed to do anything to them.

-- Ben