|
MissingH.IO.BlockIO | Portability | Haskell 2-pre | Stability | provisional | Maintainer | simons@cryp.to |
|
|
|
|
|
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 |
|
|
|
|
Static Buffer I/O
|
|
type ReadHandle = Handle |
|
type WriteHandle = Handle |
|
type ByteCount = Word16 |
|
type Capacity = Word16 |
|
data Buffer |
Constructors | | Instances | |
|
|
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
| -> ReadHandle | the input source
| -> Capacity | I/O buffer size
| -> BlockHandler st | callback
| -> st | initial callback state
| -> IO st | return 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 | | Instances | |
|
|
data ReadTimeout |
Thrown by slurp.
| Constructors | | 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 |