libuev 2.4.1
uev.h
Go to the documentation of this file.
1/* libuEv - Micro event loop library
2 *
3 * Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
4 * Copyright (c) 2013-2024 Joachim Wiberg <troglobit()gmail!com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
35
36#ifndef LIBUEV_UEV_H_
37#define LIBUEV_UEV_H_
38
39#include "private.h"
40
41#define UEV_MAX_EVENTS 10
42
43/* I/O events, signal and timer revents are always UEV_READ */
44#define UEV_NONE 0
45#define UEV_ERROR EPOLLERR
46#define UEV_READ EPOLLIN
47#define UEV_WRITE EPOLLOUT
48#define UEV_PRI EPOLLPRI
49#define UEV_HUP EPOLLHUP
50#define UEV_RDHUP EPOLLRDHUP
51#define UEV_EDGE EPOLLET
52#define UEV_ONESHOT EPOLLONESHOT
53
54/* Run flags */
55#define UEV_ONCE 1
56#define UEV_NONBLOCK 2
57
59#define uev_io_active(w) _uev_watcher_active(w)
61#define uev_signal_active(w) _uev_watcher_active(w)
63#define uev_timer_active(w) _uev_watcher_active(w)
65#define uev_cron_active(w) _uev_watcher_active(w)
67#define uev_event_active(w) _uev_watcher_active(w)
68
70typedef struct uev_ctx uev_ctx_t;
71
73typedef struct uev {
74 /* Private data for libuEv internal engine */
75 uev_private_t type;
76
77 /* Public data for users to reference */
78 int signo;
79 int fd;
81
82 /* Extra data for certain watcher types */
83 struct signalfd_siginfo siginfo;
85
97typedef void (uev_cb_t)(uev_t *w, void *arg, int events);
98
99/* Public interface */
100
102int uev_init (uev_ctx_t *ctx);
103int uev_init1 (uev_ctx_t *ctx, int maxevents);
104int uev_exit (uev_ctx_t *ctx);
105int uev_run (uev_ctx_t *ctx, int flags);
106
107int uev_io_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int events);
108int uev_io_set (uev_t *w, int fd, int events);
109int uev_io_start (uev_t *w);
110int uev_io_stop (uev_t *w);
111
112int uev_timer_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeout, int period);
113int uev_timer_set (uev_t *w, int timeout, int period);
114int uev_timer_start (uev_t *w);
115int uev_timer_stop (uev_t *w);
116
117int uev_cron_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when, time_t interval);
118int uev_cron_set (uev_t *w, time_t when, time_t interval);
119int uev_cron_start (uev_t *w);
120int uev_cron_stop (uev_t *w);
121
122int uev_signal_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo);
123int uev_signal_set (uev_t *w, int signo);
124int uev_signal_start (uev_t *w);
125int uev_signal_stop (uev_t *w);
126
127int uev_event_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg);
128int uev_event_post (uev_t *w);
129int uev_event_stop (uev_t *w);
130
131#endif /* LIBUEV_UEV_H_ */
132
Definition uev.h:73
int signo
Definition uev.h:78
int fd
Definition uev.h:79
uev_ctx_t * ctx
Definition uev.h:80
struct signalfd_siginfo siginfo
Definition uev.h:83
int uev_cron_set(uev_t *w, time_t when, time_t interval)
Definition cron.c:100
int uev_timer_start(uev_t *w)
Definition timer.c:160
int uev_exit(uev_ctx_t *ctx)
Definition uev.c:240
int uev_event_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg)
Definition event.c:46
int uev_timer_stop(uev_t *w)
Definition timer.c:179
int uev_io_stop(uev_t *w)
Definition io.c:93
int uev_timer_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeout, int period)
Definition timer.c:77
int uev_event_post(uev_t *w)
Definition event.c:70
int uev_run(uev_ctx_t *ctx, int flags)
Definition uev.c:299
int uev_cron_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when, time_t interval)
Definition cron.c:66
struct uev_ctx uev_ctx_t
Definition uev.h:70
int uev_signal_stop(uev_t *w)
Definition signal.c:147
int uev_cron_stop(uev_t *w)
Definition cron.c:156
int uev_io_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int events)
Definition io.c:44
int uev_init1(uev_ctx_t *ctx, int maxevents)
Definition uev.c:218
int uev_io_start(uev_t *w)
Definition io.c:82
int uev_init(uev_ctx_t *ctx)
Definition uev.c:191
int uev_signal_start(uev_t *w)
Definition signal.c:128
int uev_signal_set(uev_t *w, int signo)
Definition signal.c:88
int uev_event_stop(uev_t *w)
Definition event.c:92
void uev_cb_t(uev_t *w, void *arg, int events)
Definition uev.h:97
int uev_signal_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo)
Definition signal.c:52
int uev_io_set(uev_t *w, int fd, int events)
Definition io.c:65
int uev_cron_start(uev_t *w)
Definition cron.c:145
int uev_timer_set(uev_t *w, int timeout, int period)
Definition timer.c:116
struct uev uev_t