|
|
|
@@ -3,6 +3,20 @@ libuEv | Simple event loop for Linux
|
|
|
|
|
[](https://travis-ci.org/troglobit/libuev)
|
|
|
|
|
[](https://scan.coverity.com/projects/3846)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table of Contents
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
* [Introduction](#introduction)
|
|
|
|
|
* [API](#api)
|
|
|
|
|
* [Example](#example)
|
|
|
|
|
* [Build & Install](#build--install)
|
|
|
|
|
* [Origin & References](#origin--references)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
> “Why an event loop, why not use threads?”
|
|
|
|
|
|
|
|
|
|
With the advent of light-weight processes (threads) programmers these
|
|
|
|
@@ -40,7 +54,14 @@ small size overhead impact of the library. The primary target of libuEv
|
|
|
|
|
is a modern Linux system.
|
|
|
|
|
|
|
|
|
|
Experienced developers may appreciate that libuEv is built on top of
|
|
|
|
|
modern Linux APIs: epoll, timerfd and signalfd.
|
|
|
|
|
modern Linux APIs: epoll, timerfd and signalfd. Note, a certain amount
|
|
|
|
|
of care is needed when dealing with APIs that employ signalfd. For
|
|
|
|
|
details, see this article at [lwn.net](http://lwn.net/Articles/415684/).
|
|
|
|
|
|
|
|
|
|
> “Event driven software improves concurrency” -- Dave Zarzycki, Apple
|
|
|
|
|
|
|
|
|
|
See the [launchd video](http://www.youtube.com/watch?v=cD_s6Fjdri8) for
|
|
|
|
|
more info.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API
|
|
|
|
@@ -82,7 +103,7 @@ To be able to set up callbacks to events the developer first need to
|
|
|
|
|
create an *event context*, achieved by calling `uev_init()` with a
|
|
|
|
|
pointer to a local `uev_ctx_t` variable.
|
|
|
|
|
|
|
|
|
|
Events are monitored by watchers in libuEV. A watcher is nothing more
|
|
|
|
|
Events are monitored by watchers in libuEv. A watcher is nothing more
|
|
|
|
|
than a mechnism that polls a file descriptor. Register a watcher with a
|
|
|
|
|
callback to the event context by passing the `uev_ctx_t` variable, along
|
|
|
|
|
with an `uev_t` variable to each event's `_init()` function.
|
|
|
|
@@ -167,15 +188,15 @@ int main(void)
|
|
|
|
|
To compile the program, save the code as `joystick.c` and call GCC with
|
|
|
|
|
`gcc -o joystick joystick.c io.c timer.c signal.c main.c` from this
|
|
|
|
|
directory, skips using a Makefile altogether. Alternatively, call the
|
|
|
|
|
`Makefile` with `make joystick` from this directory.
|
|
|
|
|
`Makefile` with <kbd>make joystick</kbd> from this directory.
|
|
|
|
|
|
|
|
|
|
For a more complete, and perhaps more relevant example, see the code for
|
|
|
|
|
the TFTP/FTP server [uftpd](https://github.com/troglobit/uftpd). It
|
|
|
|
|
uses libuEv as a GIT submodule.
|
|
|
|
|
|
|
|
|
|
Also, see the `bench.c` program (`make bench` from within the library)
|
|
|
|
|
for [reference benchmarks](http://libev.schmorp.de/bench.html) against
|
|
|
|
|
libevent and libev.
|
|
|
|
|
Also, see the `bench.c` program (<kbd>make bench</kbd> from within the
|
|
|
|
|
library) for [reference benchmarks](http://libev.schmorp.de/bench.html)
|
|
|
|
|
against libevent and libev.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Build & Install
|
|
|
|
@@ -186,9 +207,9 @@ use GCC and GNU Make specific extensions here and there. This is not on
|
|
|
|
|
purpose and patches to correct this are most welcome. Particularly
|
|
|
|
|
patches to support *BSD and its kqueue interface.
|
|
|
|
|
|
|
|
|
|
* `make all`: The library
|
|
|
|
|
* `make test`: Test and showcase
|
|
|
|
|
* `make install`: Honors `$prefix` and `$DESTDIR` environment variables
|
|
|
|
|
* <kbd>make all</kbd>: The library
|
|
|
|
|
* <kbd>make test</kbd>: Test and showcase
|
|
|
|
|
* <kbd>make install</kbd>: Honors `$prefix` and `$DESTDIR` environment variables
|
|
|
|
|
|
|
|
|
|
Size of libuEv:
|
|
|
|
|
|
|
|
|
|