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

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 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
participants (1)
-
Simon Marlow