Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | toralf.wittner@gmail.com |
Buffer layer above epoll. Implemented using EventLoop
s.
The general usage is that first an instance of Runtime
is obtained, then
one creates as many buffers as needed. Once done with a buffer, it has
to be closed and finally the runtime should be shutdown, which kills
the event loop, e.g.
do r <- createRuntime (fromJust . toSize $ 4096) withIBuffer r stdInput $ \b -> readBuffer b >>= mapM_ print . take 10 . lines shutdownRuntime r
Please note that one has to close all buffers before calling shutdown on the runtime.
- data Runtime
- createRuntime :: Size -> IO Runtime
- shutdownRuntime :: Runtime -> IO ()
- class BufElem a where
- data IBuffer a
- createIBuffer :: BufElem a => Runtime -> Fd -> IO (IBuffer a)
- closeIBuffer :: BufElem a => Runtime -> IBuffer a -> IO ()
- withIBuffer :: BufElem a => Runtime -> Fd -> (IBuffer a -> IO ()) -> IO ()
- data OBuffer a
- createOBuffer :: BufElem a => Runtime -> Fd -> IO (OBuffer a)
- closeOBuffer :: BufElem a => Runtime -> OBuffer a -> IO ()
- withOBuffer :: BufElem a => Runtime -> Fd -> (OBuffer a -> IO ()) -> IO ()
- readBuffer :: BufElem a => IBuffer a -> IO a
- readAvail :: BufElem a => IBuffer a -> IO (Maybe a)
- readChunk :: BufElem a => IBuffer a -> IO a
- writeBuffer :: BufElem a => OBuffer a -> a -> IO ()
- flushBuffer :: OBuffer a -> IO ()
Documentation
createRuntime :: Size -> IO RuntimeSource
Creates a runtime instance where size denotes the epoll
device size (cf. create
).
shutdownRuntime :: Runtime -> IO ()Source
Stops event processing and closes this runtime (and the underlying epoll device).
Buffer Element type class. Any instance of this class can be used as a buffer element.
Zero element, e.g. empty string.
Concatenates multiple elements.
The length of one element.
Returns element minus integer.
beWrite :: Fd -> a -> IO IntSource
Writes element to Fd
, returns written length.
beRead :: Fd -> Int -> IO (a, Int)Source
Reads element of given length, returns element and actual length.
closeIBuffer :: BufElem a => Runtime -> IBuffer a -> IO ()Source
Close an IBuffer. Must not be called after shutdownRuntime
has been
invoked.
withIBuffer :: BufElem a => Runtime -> Fd -> (IBuffer a -> IO ()) -> IO ()Source
Exception safe wrapper which creates an IBuffer, passes it to the provided function and closes it afterwards.
closeOBuffer :: BufElem a => Runtime -> OBuffer a -> IO ()Source
Close an OBuffer. Must not be called after shutdownRuntime
has been
invoked.
withOBuffer :: BufElem a => Runtime -> Fd -> (OBuffer a -> IO ()) -> IO ()Source
Exception safe wrapper which creates an OBuffer, passes it to the provided function and flushes and closes it afterwards.
readBuffer :: BufElem a => IBuffer a -> IO aSource
Blocking read. Lazily returns all available contents from IBuffer
.
readAvail :: BufElem a => IBuffer a -> IO (Maybe a)Source
Non-Blocking read. Returns one chunk if available.
writeBuffer :: BufElem a => OBuffer a -> a -> IO ()Source
Non-Blocking write. Writes value to buffer which will asynchronously be written to file descriptor.
flushBuffer :: OBuffer a -> IO ()Source
Blocks until buffer is emptied.