2
* Copyright 2011 Red Hat, Inc.
4
* Permission is hereby granted, free of charge, to any person
5
* obtaining a copy of this software and associated documentation files
6
* (the "Software"), to deal in the Software without restriction,
7
* including without limitation the rights to use, copy, modify, merge,
8
* publish, distribute, sublicense, and/or sell copies of the Software,
9
* and to permit persons to whom the Software is furnished to do so,
10
* subject to the following conditions:
12
* The above copyright notice and this permission notice shall be
13
* included in all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
* An edited version of verto-libev.c, using an embedded libev with renamed
27
* symbols. The corresponding version of verto-libev.c is stored in this
28
* directory for reference, although it is not built here.
35
#include "verto-k5ev.h"
36
#include <verto-module.h>
39
#define EV_STANDALONE 1
40
/* Avoids using clock_gettime; we probably shouldn't have to do this. */
41
#define EV_USE_REALTIME 0
42
#define EV_FEATURES 0x5f /* Everything but back ends */
46
/* ev.c explicitly disables poll() on Mac or FreeBSD; fall back to select(). */
47
#define EV_USE_SELECT 1
50
static verto_mod_ctx *
53
return ev_loop_new(EVFLAG_AUTO);
56
static verto_mod_ctx *
57
k5ev_ctx_default(void)
59
return ev_default_loop(EVFLAG_AUTO);
63
k5ev_ctx_free(verto_mod_ctx *ctx)
65
if (ctx != EV_DEFAULT)
70
k5ev_ctx_run(verto_mod_ctx *ctx)
76
k5ev_ctx_run_once(verto_mod_ctx *ctx)
78
ev_run(ctx, EVRUN_ONCE);
82
k5ev_ctx_break(verto_mod_ctx *ctx)
84
ev_break(ctx, EVBREAK_ONE);
88
k5ev_ctx_reinitialize(verto_mod_ctx *ctx)
94
libev_callback(EV_P_ ev_watcher *w, int revents)
96
if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD)
97
verto_set_proc_status(w->data, ((ev_child*) w)->rstatus);
102
#define setuptype(type, ...) \
103
w.type = malloc(sizeof(ev_ ## type)); \
105
ev_ ## type ## _init(w.type, (EV_CB(type, (*))) __VA_ARGS__); \
106
ev_ ## type ## _start(ctx, w.type); \
110
static verto_mod_ev *
111
k5ev_ctx_add(verto_mod_ctx *ctx, const verto_ev *ev, verto_ev_flag *flags)
122
int events = EV_NONE;
125
*flags |= VERTO_EV_FLAG_PERSIST;
126
switch (verto_get_type(ev)) {
127
case VERTO_EV_TYPE_IO:
128
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
130
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
132
setuptype(io, libev_callback, verto_get_fd(ev), events);
133
case VERTO_EV_TYPE_TIMEOUT:
134
interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0;
135
setuptype(timer, libev_callback, interval, interval);
136
case VERTO_EV_TYPE_IDLE:
137
setuptype(idle, libev_callback);
138
case VERTO_EV_TYPE_SIGNAL:
139
setuptype(signal, libev_callback, verto_get_signal(ev));
140
case VERTO_EV_TYPE_CHILD:
141
*flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */
142
setuptype(child, libev_callback, verto_get_proc(ev), 0);
144
break; /* Not supported */
148
w.watcher->data = (void*) ev;
153
k5ev_ctx_del(verto_mod_ctx *ctx, const verto_ev *ev, verto_mod_ev *evpriv)
155
switch (verto_get_type(ev)) {
156
case VERTO_EV_TYPE_IO:
157
ev_io_stop(ctx, (ev_io*) evpriv);
159
case VERTO_EV_TYPE_TIMEOUT:
160
ev_timer_stop(ctx, (ev_timer*) evpriv);
162
case VERTO_EV_TYPE_IDLE:
163
ev_idle_stop(ctx, (ev_idle*) evpriv);
165
case VERTO_EV_TYPE_SIGNAL:
166
ev_signal_stop(ctx, (ev_signal*) evpriv);
168
case VERTO_EV_TYPE_CHILD:
169
ev_child_stop(ctx, (ev_child*) evpriv);
178
VERTO_MODULE(k5ev, NULL,
180
VERTO_EV_TYPE_TIMEOUT |
182
VERTO_EV_TYPE_SIGNAL |
183
VERTO_EV_TYPE_CHILD);
186
verto_convert_k5ev(struct ev_loop* loop)
188
return verto_convert(k5ev, 0, loop);