hlibev-0.2.1: FFI interface to libev

Network.Libev

Contents

Description

Network.Libev is a low-level binding to the libev library (http://libev.schmorp.de/). The libev documentation is available here: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod.

Synopsis

Event loops

type EvLoopPtr = Ptr EvLoopSource

Flags for evDefaultLoop

evRecommendedBackends :: IO CEvFlagTypeSource

Returns the default set of CEvFlagType flags

Event flags

type CEventType = CIntSource

CEventType is a bitfield used to flag whether a file descriptor is readable, writable, or both. Valid values are ev_read and ev_write. TODO: deprecate and replace by a datatype

type CEvFlagType = CIntSource

CEvFlagType is a bitfield used to pass flags into evDefaultLoop. Values (evflag_auto, evflag_noenv, etc.) are combined with bitwise or. TODO: replace with a newtype with a monoid instance

ev_io

type EvIoPtr = Ptr EvIoSource

type IoCallback = EvLoopPtr -> EvIoPtr -> CEventType -> IO ()Source

An IoCallback is called when a file descriptor becomes readable or writable. It takes a pointer to an ev_loop structure, a pointer to an ev_io structure, and an event mask.

mkEvIo :: IO EvIoPtrSource

Makes a new ev_io struct using malloc. You are responsible for freeing it with freeEvIo.

mkEvTimer :: IO EvTimerPtrSource

Makes a new ev_timer struct using malloc. You are responsible for freeing it with freeEvTimer.

mkIoCallback :: IoCallback -> IO (FunPtr IoCallback)Source

Wrap up an IoCallback so it can be delivered into C-land. This resource is not garbage-collected, you are responsible for freeing it with freeIoCallback.

mkTimerCallback :: TimerCallback -> IO (FunPtr TimerCallback)Source

Wrap up a TimerCallback so it can be delivered into C-land. This resource is not garbage-collected, you are responsible for freeing it with freeTimerCallback.

ev_timer

type EvTimerPtr = Ptr EvTimerSource

type TimerCallback = EvLoopPtr -> EvTimerPtr -> CEventType -> IO ()Source

A TimerCallback is called when a timer expires. It takes a pointer to an ev_loop structure, a pointer to an ev_io structure, and an (unused?) event mask.

Time functions

type EvTimestamp = CDoubleSource

Libev timestamp values are C doubles containing the (floating) number of seconds since Jan 1, 1970.

evNow :: EvLoopPtr -> IO EvTimestampSource

Fetch a the cached copy of the current time from a loop.

evTime :: IO EvTimestampSource

Fetches the current time from the operating system. Usually evNow is preferred since it avoids a context switch by returning a cached value.

C utility functions

c_accept :: CInt -> IO CIntSource

Calls accept() and sets the socket non-blocking.