epoll-0.2.2: epoll bindings

Portabilitynon-portable
Stabilityexperimental
Maintainertoralf.wittner@gmail.com

System.Linux.Epoll.Buffer

Description

Buffer layer above epoll. Implemented using EventLoops. 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.

Synopsis

Documentation

data Runtime Source

Abstract data type for buffer runtime support.

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).

class BufElem a whereSource

Buffer Element type class. Any instance of this class can be used as a buffer element.

Methods

beZero :: aSource

Zero element, e.g. empty string.

beConcat :: [a] -> aSource

Concatenates multiple elements.

beLength :: a -> IntSource

The length of one element.

beDrop :: Int -> a -> aSource

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.

Instances

data IBuffer a Source

Buffer for reading after inEvent.

createIBuffer :: BufElem a => Runtime -> Fd -> IO (IBuffer a)Source

Create buffer for inEvents.

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 b) -> IO bSource

Exception safe wrapper which creates an IBuffer, passes it to the provided function and closes it afterwards.

data OBuffer a Source

Buffer for writing after outEvent.

createOBuffer :: BufElem a => Runtime -> Fd -> IO (OBuffer a)Source

Create Buffer for outEvents.

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 b) -> IO bSource

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.

readChunk :: BufElem a => IBuffer a -> IO aSource

Blocking read. Returns one chunk from IBuffer.

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.