libuev 2.4.1
|
#include "private.h"
Go to the source code of this file.
Classes | |
struct | uev |
Macros | |
#define | UEV_MAX_EVENTS 10 |
#define | UEV_NONE 0 |
#define | UEV_ERROR EPOLLERR |
#define | UEV_READ EPOLLIN |
#define | UEV_WRITE EPOLLOUT |
#define | UEV_PRI EPOLLPRI |
#define | UEV_HUP EPOLLHUP |
#define | UEV_RDHUP EPOLLRDHUP |
#define | UEV_EDGE EPOLLET |
#define | UEV_ONESHOT EPOLLONESHOT |
#define | UEV_ONCE 1 |
#define | UEV_NONBLOCK 2 |
#define | uev_io_active(w) |
#define | uev_signal_active(w) |
#define | uev_timer_active(w) |
#define | uev_cron_active(w) |
#define | uev_event_active(w) |
Typedefs | |
typedef struct uev_ctx | uev_ctx_t |
typedef struct uev | uev_t |
typedef void | uev_cb_t(uev_t *w, void *arg, int events) |
Functions | |
int | uev_init (uev_ctx_t *ctx) |
int | uev_init1 (uev_ctx_t *ctx, int maxevents) |
int | uev_exit (uev_ctx_t *ctx) |
int | uev_run (uev_ctx_t *ctx, int flags) |
int | uev_io_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int events) |
int | uev_io_set (uev_t *w, int fd, int events) |
int | uev_io_start (uev_t *w) |
int | uev_io_stop (uev_t *w) |
int | uev_timer_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeout, int period) |
int | uev_timer_set (uev_t *w, int timeout, int period) |
int | uev_timer_start (uev_t *w) |
int | uev_timer_stop (uev_t *w) |
int | uev_cron_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when, time_t interval) |
int | uev_cron_set (uev_t *w, time_t when, time_t interval) |
int | uev_cron_start (uev_t *w) |
int | uev_cron_stop (uev_t *w) |
int | uev_signal_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo) |
int | uev_signal_set (uev_t *w, int signo) |
int | uev_signal_start (uev_t *w) |
int | uev_signal_stop (uev_t *w) |
int | uev_event_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg) |
int | uev_event_post (uev_t *w) |
int | uev_event_stop (uev_t *w) |
Micro event loop library
The latest version of this manual and the libuEv software are available at https://github.com/troglobit/libuEv/
Definition in file uev.h.
#define uev_cron_active | ( | w | ) |
#define uev_event_active | ( | w | ) |
#define uev_io_active | ( | w | ) |
#define uev_signal_active | ( | w | ) |
#define uev_timer_active | ( | w | ) |
typedef void uev_cb_t(uev_t *w, void *arg, int events) |
Generic callback for watchers, events
holds UEV_READ and/or UEV_WRITE with optional UEV_PRI (priority data available to read) and any of the UEV_HUP and/or UEV_RDHUP, which may be used to signal hang-up and peer shutdown events.
Note: UEV_ERROR conditions must be handled by all callbacks! I/O watchers may also need to check UEV_HUP. Appropriate action, e.g. restart the watcher, is up to the application and is thus delegated to the callback.
typedef struct uev_ctx uev_ctx_t |
int uev_cron_init | ( | uev_ctx_t * | ctx, |
uev_t * | w, | ||
uev_cb_t * | cb, | ||
void * | arg, | ||
time_t | when, | ||
time_t | interval ) |
Create and start an at/cron job watcher
ctx | A valid libuEv context |
w | Pointer to an uev_t watcher |
cb | Callback function for cron job |
arg | Optional callback argument |
when | First point in time to call cb |
interval | For an at job this is zero, for cron the offset interval |
For at jobs set interval
to zero and only use when
. For cron jobs, set interval
to the offset. E.g., if the job should run every five minutes set the tm_min
of struct tm to five.
Use mktime() to create the time_t arguments. The special value zero may be used for when
to denote 'now', where 'now' is when the event loop is started. You can also treat time_t simply as a signed integer. E.g., set interval
to 3600 to create a cron job that runs every hour.
errno
set on error. int uev_cron_set | ( | uev_t * | w, |
time_t | when, | ||
time_t | interval ) |
int uev_cron_start | ( | uev_t * | w | ) |
int uev_cron_stop | ( | uev_t * | w | ) |
int uev_event_post | ( | uev_t * | w | ) |
int uev_event_stop | ( | uev_t * | w | ) |
int uev_exit | ( | uev_ctx_t * | ctx | ) |
int uev_init | ( | uev_ctx_t * | ctx | ) |
Create an event loop context
Create an event loop context
ctx | Pointer to an uev_ctx_t context to be initialized |
This function calls uev_init1() with maxevents
set to UEV_MAX_EVENTS
int uev_init1 | ( | uev_ctx_t * | ctx, |
int | maxevents ) |
Create an event loop context
ctx | Pointer to an uev_ctx_t context to be initialized |
maxevents | Maximum number of events in event cache [1, 10] |
This function is the same as uev_init() except for the maxevents
argument, max UEV_MAX_EVENTS, which controls the number of events in the event cache returned to the main loop.
In cases where you have multiple events pending in the cache and some event may cause later ones, already sent by the kernel to userspace, to be deleted the pointer returned to the event loop for this later event may be deleted.
There are two ways around this (accessing deleted memory):
maxevents
to 1Create an I/O watcher
ctx | A valid libuEv context |
w | Pointer to an uev_t watcher |
cb | I/O callback |
arg | Optional callback argument |
fd | File descriptor to watch, or -1 to register an empty watcher |
events | Events to watch for: UEV_READ, UEV_WRITE, UEV_EDGE, UEV_ONESHOT |
errno
set on error. int uev_io_set | ( | uev_t * | w, |
int | fd, | ||
int | events ) |
int uev_io_start | ( | uev_t * | w | ) |
int uev_io_stop | ( | uev_t * | w | ) |
int uev_run | ( | uev_ctx_t * | ctx, |
int | flags ) |
Start the event loop
ctx | A valid libuEv context |
flags | A mask of UEV_ONCE and UEV_NONBLOCK, or zero |
With flags
set to UEV_ONCE the event loop returns after the first event has been served, useful for instance to set a timeout on a file descriptor. If flags
also has the UEV_NONBLOCK flag set the event loop will return immediately if no event is pending, useful when run inside another event loop.
int uev_signal_set | ( | uev_t * | w, |
int | signo ) |
int uev_signal_start | ( | uev_t * | w | ) |
int uev_signal_stop | ( | uev_t * | w | ) |
int uev_timer_init | ( | uev_ctx_t * | ctx, |
uev_t * | w, | ||
uev_cb_t * | cb, | ||
void * | arg, | ||
int | timeout, | ||
int | period ) |
Create and start a timer watcher
ctx | A valid libuEv context |
w | Pointer to an uev_t watcher |
cb | Callback function |
arg | Optional callback argument |
timeout | Timeout in milliseconds before cb is called |
period | For periodic timers this is the period time that timeout is reset to |
This function creates, and optionally starts, a timer watcher. There are two types of timers: one-shot and periodic.
One-shot timers only use timeout
, period
is zero.
Periodic timers can either start their life disabled, with timeout
set to zero, or with the same value as period
.
When the timeout expires, for either of the two types, cb
is called, with the optional arg
argument. A one-shot timer ends its life there, while a periodic task's timeout
is reset to the period
and restarted.
A timer is automatically started if the event loop is already running, otherwise it is kept on hold until triggered by calling uev_run().
errno
set on error. int uev_timer_set | ( | uev_t * | w, |
int | timeout, | ||
int | period ) |
Reset a timer
w | Watcher to reset |
timeout | Timeout in milliseconds before cb is called, zero disarms timer |
period | For periodic timers this is the period time that timeout is reset to |
Note, the timeout
value must be non-zero. Setting it to zero disarms the timer. This is the behavior of the underlying Linux function timerfd_settimer(2)
errno
set on error. int uev_timer_start | ( | uev_t * | w | ) |