MissingH-0.16.0: ContentsIndex
MissingH.IO.BlockIO
PortabilityHaskell 2-pre
Stabilityprovisional
Maintainersimons@cryp.to
Contents
Static Buffer I/O
BlockHandler and I/O Driver
Handler Combinators
I/O Exceptions
Internal Helper Functions
Description
runLoop drives a BlockHandler with data read from the input stream until hIsEOF ensues. Everything else has to be done by the callback; runLoop just does the I/O. But it does it fast.
Synopsis
type ReadHandle = Handle
type WriteHandle = Handle
type ByteCount = Word16
type Capacity = Word16
data Buffer = Buf !Capacity !(Ptr Word8) !ByteCount
withBuffer :: Capacity -> (Buffer -> IO a) -> IO a
flush :: ByteCount -> Buffer -> IO Buffer
slurp :: Timeout -> ReadHandle -> Buffer -> IO (Maybe Buffer)
type BlockHandler st = Buffer -> st -> IO (Buffer, st)
runLoopNB :: (st -> Timeout) -> (Exception -> st -> IO st) -> ReadHandle -> Capacity -> BlockHandler st -> st -> IO st
runLoop :: ReadHandle -> Capacity -> BlockHandler st -> st -> IO st
type StreamHandler st = [Word8] -> st -> IO (ByteCount, st)
handleStream :: StreamHandler st -> BlockHandler st
data BufferOverflow = BufferOverflow ReadHandle Buffer
data ReadTimeout = ReadTimeout Timeout ReadHandle Buffer
handleEOF :: IO a -> IO (Maybe a)
strstr :: [Word8] -> [Word8] -> Maybe Int
splitList :: Eq a => [a] -> [a] -> [[a]]
(?) :: Bool -> (a, a) -> a
Static Buffer I/O
type ReadHandle = Handle
type WriteHandle = Handle
type ByteCount = Word16
type Capacity = Word16
data Buffer
Constructors
Buf !Capacity !(Ptr Word8) !ByteCount
show/hide Instances
Eq Buffer
Show Buffer
Typeable Buffer
withBuffer :: Capacity -> (Buffer -> IO a) -> IO a
Run the given computation with an initialized, empty Buffer. The buffer is gone when the computation returns.
flush :: ByteCount -> Buffer -> IO Buffer
Drop the first n <= size octets from the buffer.
slurp :: Timeout -> ReadHandle -> Buffer -> IO (Maybe Buffer)
If there is space, read and append more octets; then return the modified buffer. In case of hIsEOF, Nothing is returned. If the buffer is full already, throwDyn a BufferOverflow exception. When the timeout exceeds, ReadTimeout is thrown.
BlockHandler and I/O Driver
type BlockHandler st = Buffer -> st -> IO (Buffer, st)
A callback function suitable for use with runLoop takes a buffer and a state, then returns a modified buffer and a modified state. Usually the callback will use slurp to remove data it has processed already.
runLoopNB
:: (st -> Timeout)user state provides timeout
-> (Exception -> st -> IO st)user provides I/O error handler
-> ReadHandlethe input source
-> CapacityI/O buffer size
-> BlockHandler stcallback
-> stinitial callback state
-> IO streturn final callback state
Our main I/O driver.
runLoop :: ReadHandle -> Capacity -> BlockHandler st -> st -> IO st
A variant which won't time out and will just throw all exceptions.
Handler Combinators
type StreamHandler st = [Word8] -> st -> IO (ByteCount, st)
Signal how many bytes have been consumed from the front of the list; these octets will be dropped.
handleStream :: StreamHandler st -> BlockHandler st
I/O Exceptions
data BufferOverflow
Thrown by slurp.
Constructors
BufferOverflow ReadHandle Buffer
show/hide Instances
data ReadTimeout
Thrown by slurp.
Constructors
ReadTimeout Timeout ReadHandle Buffer
show/hide Instances
Internal Helper Functions
handleEOF :: IO a -> IO (Maybe a)
Return Nothing if the given computation throws an isEOFError exception. Used by slurp.
strstr :: [Word8] -> [Word8] -> Maybe Int
Our version of C's strstr(3).
splitList :: Eq a => [a] -> [a] -> [[a]]
Split a list by some delimiter. Will soon be provided by Data.List.
(?) :: Bool -> (a, a) -> a
Shorthand for if-then-else. Will soon by provided by Data.Bool.
Produced by Haddock version 0.8