These are global function pointers, initialized by default to the standard C
library functions malloc, realloc, and free.
Applications using liboop may reset these pointers to allocation and
deallocation routines with a compatible interface; libraries should use
these function pointers wherever possible to allocate and release memory.
These pointers are normally set before calling any liboop code; if they
are changed during operation, the new oop_free and
oop_realloc functions should be
capable of handling memory obtained with the old oop_malloc.
oop_malloc
This function allocates a block of memory of size len and returns
a pointer to the start of the block. If allocation fails, NULL is returned.
This function resizes a block of memory at ptr to have the new
length len. If ptr is NULL, fresh memory is allocated.
If len is zero, memory is freed and NULL is returned.
If ptr is NULL and len is zero, nothing is done and NULL
is returned. If reallocation fails, NULL is returned.
oop_free
This function releases a block of memory, designated by ptr,
previously allocated by oop_malloc. Once released, the memory may
be immediately overwritten, and/or reused by subsequent calls to
oop_malloc.
*Compatibility note: oop_realloc
is only available in version 0.7 or newer.
Liboop is primarily an interface definition. It defines an interface
which components may use to request notification when an event
(activity on a file descriptor, the real-time clock reaches a certain value,
a particular signal is received) occurs. The component which owns the event
loop -- the component whose code is active when the system is idle --
implements the interface; it is an event source. Components which
are interested in events register themselves with the event source; they are
event sinks. Event sinks may themselves source other, higher-level
events, but that is outside liboop's scope.
Control flow.
During initialization, the event source is created. At least one event sink
is also created, and registered with the event source. Once initialization
completes, control is transferred to the event source, which (at its core)
waits for events, usually using a system function like select() or poll().
When an event occurs, the event source gives a callback to all the
event sinks which registered interest in that event.
During callbacks, the event sinks react to the event as appropriate (usually
performing some I/O, or at least modifying internal state). Event sinks for
events which are no longer relevant may be unregistered; new event sinks may
be registered for additional events. Each event sink, when it finishes,
returns a value which tells the event source whether to continue processing
events or whether to terminate.
While the event source must be fully reentrant (registration and deregistration
may, and indeed usually are, performed within the context of an event), event
sinks need not be; no event sink will be called while another event sink is
active.
If no event sink instructs the event source to terminate, the event source
continues waiting for events. Otherwise, the event source returns to its
caller, which usually shuts down the system.
The system event source.
Liboop comes with a single "reference" implementation of an event source.
This event source uses select() to dispatch events. Most programs built
around liboop will probably use the standard system event source; legacy
programs with their own event loop, or programs with specialized needs may
implement their own event source.
Adapters.
Liboop supports adapters to enable legacy components to use the liboop
interface. For example, many widget sets have their own event loop and their
own mechanism for registering callbacks on timeouts and file descriptor
activity; liboop uses source adapters that accept registration,
register corresponding callbacks with the widget set's event loop, and route
events appropriately. Such adapters let general-purpose liboop-based
components work in an application based on that widget set.
Similarly, some components are designed to work in a non-blocking fashion, and
they might be used with a sink adapter to work with liboop. An
asynchronous DNS query package, for example, could work as a liboop sink that
ultimately generates a higher-level "success" or "failure" callback to the
invoking routine.
Code.
Liboop's abstract event source interface is implemented as a structure
containing C function pointers. These functions accept a pointer to the
structure as their first argument; sources are expected to include their
own data (in whatever format) with the core function pointers. Callbacks
are also C function pointers, with "void *" arguments to pass data.
For more about the liboop interface, see the reference.
liboop home
liboop-www/index.html 0000664 0000000 0000000 00000012665 13035253175 0015177 0 ustar 00root root 0000000 0000000
liboop home page
Liboop is a low-level event loop management library for POSIX-based operating
systems. It supports the development of modular, multiplexed applications
which may respond to events from several sources. It replaces the "select()
loop" and allows the registration of event handlers for file and network I/O,
timers and signals. Since processes use these mechanisms for almost all
external communication, liboop can be used as the basis for almost any
application.
Version 1.0.1 released, including a few accumulated bug fixes and
a new function oop_signal_new_flags(), with an additional flags
argument to support use of the SA_RESTART option when signal handlers
are registered.
7 July 2010
Dan Egnor transfers maintainership of liboop to Niels Mller and
Per Cederqvist. The repository is converted to Git. The web pages
are currently available at http://www.lysator.liu.se/liboop/.
27 October 2003
Version 1.0 released. (The number has no special meaning, it's just
the next increment.) The build is little more robust now, and you can enable
and disable specific adapters in the configure script. The ADNS adapter
returns error messages, the GLib adapter works with GLib 2, and there's a
new oop_sys_run_once() function so you can poll an event source.
11 January 2003
Version 0.9 released. A memory leak when creating and destroying the
system event source was fixed, the robustness of signal handling is improved,
and some minor portability problems were fixed.
18 September 2001
Version 0.8 released, including a source adapter
for Tcl/Tk. (0.7 was never
announced.)
Note that while liboop is
covered by the lesser GPL, ADNS is covered by the full GPL,
and therefore any program which uses ADNS with (or without) liboop must
support distribution under the terms of the full GPL.
Version 0.1 released. This is a very, very simple initial release that
should nevertheless work as a functional event loop. No adapters are included
yet. Testing is minimal, but give it a whirl!