libuev 2.4.1
uev.c File Reference
#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"

Go to the source code of this file.

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)
 
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)
 

Detailed Description

Micro event loop library

Definition in file uev.c.

Function Documentation

◆ _uev_watcher_active()

int _uev_watcher_active ( uev_t * w)

Definition at line 156 of file uev.c.

◆ _uev_watcher_init()

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 )

Definition at line 75 of file uev.c.

◆ _uev_watcher_rearm()

int _uev_watcher_rearm ( uev_t * w)

Definition at line 165 of file uev.c.

◆ _uev_watcher_start()

int _uev_watcher_start ( uev_t * w)

Definition at line 94 of file uev.c.

◆ _uev_watcher_stop()

int _uev_watcher_stop ( uev_t * w)

Definition at line 133 of file uev.c.

◆ 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.

Definition at line 240 of file uev.c.

◆ 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.

Definition at line 191 of file uev.c.

◆ 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.

Definition at line 218 of file uev.c.

◆ 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.

Definition at line 299 of file uev.c.