5 Commits
Author SHA1 Message Date
Joachim Nilsson 0e3d6ebb1d Minor improvement in how build is echoed to screen.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 23:51:24 +01:00
Joachim Nilsson 66194a8645 Update Introduction with cautionary warning about signalfd.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 14:27:32 +01:00
Joachim Nilsson 0f18e4fcc0 Minor update.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-22 01:22:56 +01:00
Joachim Nilsson 96a497b03e Simplify test.c example, no need to stop timer before exit.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-11 14:05:41 +01:00
Joachim Nilsson 2a6697d514 Add ToC and some kbd markup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-11 14:04:48 +01:00
3 changed files with 35 additions and 13 deletions

No files matched your search

+2 -1
View File
@@ -38,6 +38,7 @@ CPPFLAGS += -W -Wall -Werror
ARFLAGS = crus ARFLAGS = crus
JUNK = *~ *.bak *.map .*.d DEADJOE *.gdb *.elf core core.* JUNK = *~ *.bak *.map .*.d DEADJOE *.gdb *.elf core core.*
ROOTDIR ?= $(shell pwd)
LIBNAME = $(NAME) LIBNAME = $(NAME)
prefix ?= /usr/local prefix ?= /usr/local
libdir ?= $(prefix)/lib libdir ?= $(prefix)/lib
@@ -57,7 +58,7 @@ TARGET = $(STATICLIB) $(SOLIB)
# Pattern rules # Pattern rules
.c.o: .c.o:
@printf " CC $@\n" @printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
# Smart autodependecy generation via GCC -M. # Smart autodependecy generation via GCC -M.
+30 -9
View File
@@ -3,6 +3,20 @@ libuEv | Simple event loop for Linux
[![Build Status](https://travis-ci.org/troglobit/libuev.png?branch=master)](https://travis-ci.org/troglobit/libuev) [![Build Status](https://travis-ci.org/troglobit/libuev.png?branch=master)](https://travis-ci.org/troglobit/libuev)
[![Coverity Scan Status](https://scan.coverity.com/projects/3846/badge.svg)](https://scan.coverity.com/projects/3846) [![Coverity Scan Status](https://scan.coverity.com/projects/3846/badge.svg)](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?” > “Why an event loop, why not use threads?”
With the advent of light-weight processes (threads) programmers these 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. is a modern Linux system.
Experienced developers may appreciate that libuEv is built on top of 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 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 create an *event context*, achieved by calling `uev_init()` with a
pointer to a local `uev_ctx_t` variable. 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 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 callback to the event context by passing the `uev_ctx_t` variable, along
with an `uev_t` variable to each event's `_init()` function. 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 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 `gcc -o joystick joystick.c io.c timer.c signal.c main.c` from this
directory, skips using a Makefile altogether. Alternatively, call the 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 For a more complete, and perhaps more relevant example, see the code for
the TFTP/FTP server [uftpd](https://github.com/troglobit/uftpd). It the TFTP/FTP server [uftpd](https://github.com/troglobit/uftpd). It
uses libuEv as a GIT submodule. uses libuEv as a GIT submodule.
Also, see the `bench.c` program (`make bench` from within the library) Also, see the `bench.c` program (<kbd>make bench</kbd> from within the
for [reference benchmarks](http://libev.schmorp.de/bench.html) against library) for [reference benchmarks](http://libev.schmorp.de/bench.html)
libevent and libev. against libevent and libev.
Build & Install 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 purpose and patches to correct this are most welcome. Particularly
patches to support *BSD and its kqueue interface. patches to support *BSD and its kqueue interface.
* `make all`: The library * <kbd>make all</kbd>: The library
* `make test`: Test and showcase * <kbd>make test</kbd>: Test and showcase
* `make install`: Honors `$prefix` and `$DESTDIR` environment variables * <kbd>make install</kbd>: Honors `$prefix` and `$DESTDIR` environment variables
Size of libuEv: Size of libuEv:
+3 -3
View File
@@ -42,17 +42,17 @@ static uev_t *watchdog;
static void lifetime_cb(uev_ctx_t *ctx, uev_t UNUSED(*w), void *arg, int UNUSED(events)) static void lifetime_cb(uev_ctx_t *ctx, uev_t UNUSED(*w), void *arg, int UNUSED(events))
{ {
fprintf(stderr, "\nLifetime exceeded %p\n", arg); fprintf(stderr, "\nLifetime exceeded, program completed successfully! (arg:%p)\n", arg);
uev_exit(ctx); uev_exit(ctx);
} }
/* The pipe watchdog, if it triggers we haven't received data in time. */ /* The pipe watchdog, if it triggers we haven't received data in time. */
static void timeout_cb(uev_ctx_t *ctx, uev_t *w, void *arg, int UNUSED(events)) static void timeout_cb(uev_ctx_t *ctx, uev_t *UNUSED(w), void *arg, int UNUSED(events))
{ {
watchdog = NULL; watchdog = NULL;
fprintf(stderr, "\nTimeout exceeded %p\n", arg); fprintf(stderr, "\nTimeout exceeded %p\n", arg);
uev_timer_stop(w); // uev_timer_stop(w); <-- No need to stop timers with period=0 :)
uev_exit(ctx); uev_exit(ctx);
} }