libuev
Functions
uev.c File Reference

Micro event loop library. More...

#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/signalfd.h>
#include <unistd.h>
#include "uev.h"
Include dependency graph for uev.c:

Functions

int _uev_watcher_init (uev_ctx_t *ctx, uev_t *w, uev_type_t type, uev_cb_t *cb, void *arg, int fd, int events)
 
int _uev_watcher_start (uev_t *w)
 
int _uev_watcher_stop (uev_t *w)
 
int _uev_watcher_active (uev_t *w)
 
int _uev_watcher_rearm (uev_t *w)
 
int uev_init (uev_ctx_t *ctx)
 Create an event loop context. More...
 
int uev_init1 (uev_ctx_t *ctx, int maxevents)
 Create an event loop context. More...
 
int uev_exit (uev_ctx_t *ctx)
 Terminate the event loop. More...
 
int uev_run (uev_ctx_t *ctx, int flags)
 Start the event loop. More...
 

Detailed Description

Micro event loop library.

Function Documentation

◆ uev_exit()

int uev_exit ( uev_ctx_t ctx)

Terminate the event loop.

Parameters
ctxA valid libuEv context
Returns
POSIX OK(0) or non-zero with errno set on error.

◆ uev_init()

int uev_init ( uev_ctx_t ctx)

Create an event loop context.

Parameters
ctxPointer to an uev_ctx_t context to be initialized

This function calls uev_init1() with maxevents set to UEV_MAX_EVENTS

Returns
POSIX OK(0) on success, or non-zero on error.

◆ uev_init1()

int uev_init1 ( uev_ctx_t ctx,
int  maxevents 
)

Create an event loop context.

Parameters
ctxPointer to an uev_ctx_t context to be initialized
maxeventsMaximum 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):

  1. use this function to initialize your event loop and set maxevents to 1
  2. use a free list in you application that you garbage collect at intervals relevant to your application
Returns
POSIX OK(0) on success, or non-zero on error.

◆ uev_run()

int uev_run ( uev_ctx_t ctx,
int  flags 
)

Start the event loop.

Parameters
ctxA valid libuEv context
flagsA 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.

Returns
POSIX OK(0) upon successful termination of the event loop, or non-zero on error.