commit 778bd7d324d356469c7433f656124b61178df50c
Author: Nathaniel McCallum <npmccallum(a)redhat.com>
Date: Wed Jun 29 14:37:39 2011 -0400
[all] move priority and io flags into the vertoEvFlag enum
src/verto-glib.c | 24 +++++++++---------
src/verto-libev.c | 6 ++--
src/verto-libevent.c | 22 +++++++++------
src/verto-tevent.c | 6 ++--
src/verto.c | 68 +++++++++++++------------------------------------
src/verto.h | 66 ++++++++++++------------------------------------
tests/child.c | 6 ++--
tests/idle.c | 7 ++---
tests/read.c | 7 +++--
tests/signal.c | 8 ++---
tests/timeout.c | 6 ++--
tests/write.c | 21 ++++++---------
12 files changed, 91 insertions(+), 156 deletions(-)
---
diff --git a/src/verto-glib.c b/src/verto-glib.c
index 5104c4c..9376d94 100644
--- a/src/verto-glib.c
+++ b/src/verto-glib.c
@@ -27,13 +27,6 @@
#include <verto-glib.h>
#include <verto-module.h>
-/* DEFAULT, LOW, MEDIUM, HIGH */
-static gint priority_map[4] = {
- G_PRIORITY_DEFAULT,
- G_PRIORITY_LOW,
- G_PRIORITY_DEFAULT_IDLE,
- G_PRIORITY_HIGH };
-
struct glibEvCtx {
GMainContext *context;
GMainLoop *loop;
@@ -122,8 +115,9 @@ glib_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
{
struct glibEv *gev = NULL;
enum vertoEvType type = verto_get_type(ev);
+ enum vertoEvFlag flags = verto_get_flags(ev);
- *persists = verto_get_flags(ev) & VERTO_EV_FLAG_PERSIST;
+ *persists = flags & VERTO_EV_FLAG_PERSIST;
gev = g_new0(struct glibEv, 1);
if (!gev)
@@ -131,15 +125,15 @@ glib_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
switch (type) {
case VERTO_EV_TYPE_IO:
- gev->chan = g_io_channel_unix_new(verto_get_io_fd(ev));
+ gev->chan = g_io_channel_unix_new(verto_get_fd(ev));
if (!gev->chan)
goto error;
g_io_channel_set_close_on_unref(gev->chan, FALSE);
GIOCondition cond = 0;
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_READ)
+ if (flags & VERTO_EV_FLAG_IO_READ)
cond |= G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_WRITE)
+ if (flags & VERTO_EV_FLAG_IO_WRITE)
cond |= G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
gev->src = g_io_create_watch(gev->chan, cond);
break;
@@ -174,8 +168,14 @@ glib_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
else
g_source_set_callback(gev->src, glib_callback, (void *) ev, NULL);
+ if (flags & VERTO_EV_FLAG_PRIORITY_HIGH)
+ g_source_set_priority(gev->src, G_PRIORITY_HIGH);
+ else if (flags & VERTO_EV_FLAG_PRIORITY_MEDIUM)
+ g_source_set_priority(gev->src, G_PRIORITY_DEFAULT_IDLE);
+ else if (flags & VERTO_EV_FLAG_PRIORITY_LOW)
+ g_source_set_priority(gev->src, G_PRIORITY_LOW);
+
g_source_set_can_recurse(gev->src, FALSE);
- g_source_set_priority(gev->src, priority_map[verto_get_priority(ev)]);
if (g_source_attach(gev->src, ((struct glibEvCtx*) ctx)->context) == 0)
goto error;
diff --git a/src/verto-libev.c b/src/verto-libev.c
index 1409033..76f9dcc 100644
--- a/src/verto-libev.c
+++ b/src/verto-libev.c
@@ -86,11 +86,11 @@ libev_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
*persists = true;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_READ)
+ if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
events |= EV_READ;
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_WRITE)
+ if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
events |= EV_WRITE;
- setuptype(io, ev, libev_callback, verto_get_io_fd(ev), events);
+ setuptype(io, ev, libev_callback, verto_get_fd(ev), events);
case VERTO_EV_TYPE_TIMEOUT:
interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0;
setuptype(timer, ev, libev_callback, interval, interval);
diff --git a/src/verto-libevent.c b/src/verto-libevent.c
index 983c95b..b3497a8 100644
--- a/src/verto-libevent.c
+++ b/src/verto-libevent.c
@@ -36,9 +36,6 @@
* sense of "global." */
extern struct event_base *event_global_current_base_;
-/* DEFAULT, LOW, MEDIUM, HIGH */
-static const int priority_map[4] = { 1, 2, 1, 0 };
-
static void
libevent_ctx_free(void *priv)
{
@@ -77,19 +74,20 @@ libevent_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
struct timeval *timeout = NULL;
struct timeval tv;
int flags = 0;
+ enum vertoEvFlag evflags = verto_get_flags(ev);
- *persists = verto_get_flags(ev) & VERTO_EV_FLAG_PERSIST;
+ *persists = evflags & VERTO_EV_FLAG_PERSIST;
if (*persists)
flags |= EV_PERSIST;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_READ)
+ if (evflags & VERTO_EV_FLAG_IO_READ)
flags |= EV_READ;
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_WRITE)
+ if (evflags & VERTO_EV_FLAG_IO_WRITE)
flags |= EV_WRITE;
- priv = event_new(ctx, verto_get_io_fd(ev), flags,
- libevent_callback, (void *) ev);
+ priv = event_new(ctx, verto_get_fd(ev), flags, libevent_callback,
+ (void *) ev);
break;
case VERTO_EV_TYPE_TIMEOUT:
timeout = &tv;
@@ -111,7 +109,13 @@ libevent_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
if (!priv)
return NULL;
- event_priority_set(priv, priority_map[verto_get_priority(ev)]);
+ if (evflags & VERTO_EV_FLAG_PRIORITY_HIGH)
+ event_priority_set(priv, 0);
+ else if (evflags & VERTO_EV_FLAG_PRIORITY_MEDIUM)
+ event_priority_set(priv, 1);
+ else if (evflags & VERTO_EV_FLAG_PRIORITY_LOW)
+ event_priority_set(priv, 2);
+
event_add(priv, timeout);
return priv;
}
diff --git a/src/verto-tevent.c b/src/verto-tevent.c
index c605955..34a3a70 100644
--- a/src/verto-tevent.c
+++ b/src/verto-tevent.c
@@ -87,11 +87,11 @@ tevent_ctx_add(void *ctx, const struct vertoEv *ev, bool *persists)
*persists = true;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_READ)
+ if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
flags |= TEVENT_FD_READ;
- if (verto_get_io_flags(ev) & VERTO_EV_IO_FLAG_WRITE)
+ if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
flags |= TEVENT_FD_WRITE;
- return tevent_add_fd(tctx(ctx), tctx(ctx), verto_get_io_fd(ev),
+ return tevent_add_fd(tctx(ctx), tctx(ctx), verto_get_fd(ev),
flags, tevent_fd_cb, (void *) ev);
case VERTO_EV_TYPE_TIMEOUT:
*persists = false;
diff --git a/src/verto.c b/src/verto.c
index 2f1bdb5..d1b62d6 100644
--- a/src/verto.c
+++ b/src/verto.c
@@ -54,16 +54,10 @@ struct vertoChild {
int status;
};
-struct vertoIO {
- int fd;
- enum vertoEvIOFlag flags;
-};
-
struct vertoEv {
struct vertoEv *next;
struct vertoEvCtx *ctx;
enum vertoEvType type;
- enum vertoEvPriority priority;
vertoCallback callback;
void *priv;
void *modpriv;
@@ -72,10 +66,10 @@ struct vertoEv {
size_t depth;
bool deleted;
union {
+ int fd;
int signal;
time_t interval;
struct vertoChild child;
- struct vertoIO io;
} option;
};
@@ -224,25 +218,19 @@ load_module(const char *impl, void **dll, const struct vertoModule **module)
}
static inline struct vertoEv *
-make_ev(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- vertoCallback callback, void *priv, enum vertoEvType type,
- enum vertoEvFlag flags)
+make_ev(struct vertoEvCtx *ctx, vertoCallback callback, void *priv,
+ enum vertoEvType type, enum vertoEvFlag flags)
{
struct vertoEv *ev = NULL;
if (!ctx || !callback)
return NULL;
- priority = priority < _VERTO_EV_PRIORITY_MAX + 1
- ? priority
- : VERTO_EV_PRIORITY_DEFAULT;
-
ev = malloc(sizeof(struct vertoEv));
if (ev) {
memset(ev, 0, sizeof(struct vertoEv));
ev->ctx = ctx;
ev->type = type;
- ev->priority = priority;
ev->callback = callback;
ev->priv = priv;
ev->flags = flags;
@@ -399,7 +387,7 @@ verto_break(struct vertoEvCtx *ctx)
}
#define doadd(set, type) \
- struct vertoEv *ev = make_ev(ctx, priority, callback, priv, type, flags); \
+ struct vertoEv *ev = make_ev(ctx, callback, priv, type, flags); \
if (ev) { \
set; \
ev->modpriv = ctx->funcs.ctx_add(ctx->modpriv, ev, &ev->persists); \
@@ -412,36 +400,31 @@ verto_break(struct vertoEvCtx *ctx)
return ev;
struct vertoEv *
-verto_add_io(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv, int fd,
- enum vertoEvIOFlag ioflags)
+verto_add_io(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, int fd)
{
- if (fd < 0)
+ if (fd < 0 || !(flags & (VERTO_EV_FLAG_IO_READ | VERTO_EV_FLAG_IO_WRITE)))
return NULL;
- doadd(ev->option.io.fd = fd;
- ev->option.io.flags = ioflags,
- VERTO_EV_TYPE_IO);
+ doadd(ev->option.fd = fd, VERTO_EV_TYPE_IO);
}
struct vertoEv *
-verto_add_timeout(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv,
- time_t interval)
+verto_add_timeout(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, time_t interval)
{
doadd(ev->option.interval = interval, VERTO_EV_TYPE_TIMEOUT);
}
struct vertoEv *
-verto_add_idle(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv)
+verto_add_idle(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv)
{
doadd(, VERTO_EV_TYPE_IDLE);
}
struct vertoEv *
-verto_add_signal(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv,
- int signal)
+verto_add_signal(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, int signal)
{
if (signal < 0 || signal == SIGCHLD)
return NULL;
@@ -451,9 +434,8 @@ verto_add_signal(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
}
struct vertoEv *
-verto_add_child(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv,
- pid_t pid)
+verto_add_child(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, pid_t pid)
{
if (pid < 1 || (flags & VERTO_EV_FLAG_PERSIST)) /* persist makes no sense */
return NULL;
@@ -472,12 +454,6 @@ verto_get_type(const struct vertoEv *ev)
return ev->type;
}
-enum vertoEvPriority
-verto_get_priority(const struct vertoEv *ev)
-{
- return ev->priority;
-}
-
enum vertoEvFlag
verto_get_flags(const struct vertoEv *ev)
{
@@ -485,21 +461,13 @@ verto_get_flags(const struct vertoEv *ev)
}
int
-verto_get_io_fd(const struct vertoEv *ev)
+verto_get_fd(const struct vertoEv *ev)
{
if (ev && (ev->type & VERTO_EV_TYPE_IO))
- return ev->option.io.fd;
+ return ev->option.fd;
return -1;
}
-enum vertoEvIOFlag
-verto_get_io_flags(const struct vertoEv *ev)
-{
- if (ev && (ev->type & VERTO_EV_TYPE_IO))
- return ev->option.io.flags;
- return VERTO_EV_IO_FLAG_NONE;
-}
-
time_t
verto_get_interval(const struct vertoEv *ev)
{
diff --git a/src/verto.h b/src/verto.h
index a77bcee..420720c 100644
--- a/src/verto.h
+++ b/src/verto.h
@@ -42,25 +42,15 @@ enum vertoEvType {
_VERTO_EV_TYPE_MAX = VERTO_EV_TYPE_CHILD
};
-enum vertoEvPriority {
- VERTO_EV_PRIORITY_DEFAULT = 0,
- VERTO_EV_PRIORITY_LOW = 1,
- VERTO_EV_PRIORITY_MEDIUM = 2,
- VERTO_EV_PRIORITY_HIGH = 3,
- _VERTO_EV_PRIORITY_MAX = VERTO_EV_PRIORITY_HIGH
-};
-
enum vertoEvFlag {
VERTO_EV_FLAG_NONE = 0,
VERTO_EV_FLAG_PERSIST = 1,
- _VERTO_EV_FLAG_MAX = VERTO_EV_FLAG_PERSIST
-};
-
-enum vertoEvIOFlag {
- VERTO_EV_IO_FLAG_NONE = 0,
- VERTO_EV_IO_FLAG_READ = 1,
- VERTO_EV_IO_FLAG_WRITE = 1 << 1,
- _VERTO_EV_IO_FLAG_MAX = VERTO_EV_IO_FLAG_WRITE
+ VERTO_EV_FLAG_PRIORITY_LOW = 1 << 1,
+ VERTO_EV_FLAG_PRIORITY_MEDIUM = 1 << 2,
+ VERTO_EV_FLAG_PRIORITY_HIGH = 1 << 3,
+ VERTO_EV_FLAG_IO_READ = 1 << 4,
+ VERTO_EV_FLAG_IO_WRITE = 1 << 5,
+ _VERTO_EV_FLAG_MAX = VERTO_EV_FLAG_IO_WRITE
};
typedef void (*vertoCallback)(struct vertoEvCtx *ctx, struct vertoEv *ev);
@@ -213,9 +203,8 @@ verto_break(struct vertoEvCtx *ctx);
* @return The vertoEv registered with the event context.
*/
struct vertoEv *
-verto_add_io(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv, int fd,
- enum vertoEvIOFlag ioflags);
+verto_add_io(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, int fd);
/**
* Adds a callback executed after a period of time.
@@ -240,9 +229,8 @@ verto_add_io(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
* @return The vertoEv registered with the event context.
*/
struct vertoEv *
-verto_add_timeout(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv,
- time_t interval);
+verto_add_timeout(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, time_t interval);
/**
* Adds a callback executed when there is nothing else to do.
@@ -266,8 +254,8 @@ verto_add_timeout(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
* @return The vertoEv registered with the event context.
*/
struct vertoEv *
-verto_add_idle(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv);
+verto_add_idle(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv);
/**
* Adds a callback executed when a signal is received.
@@ -303,9 +291,8 @@ verto_add_idle(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
* @return The vertoEv registered with the event context.
*/
struct vertoEv *
-verto_add_signal(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv,
- int signal);
+verto_add_signal(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, int signal);
/**
* Adds a callback executed when a child process exits.
@@ -330,9 +317,8 @@ verto_add_signal(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
* @return The vertoEv registered with the event context.
*/
struct vertoEv *
-verto_add_child(struct vertoEvCtx *ctx, enum vertoEvPriority priority,
- enum vertoEvFlag flags, vertoCallback callback, void *priv,
- pid_t pid);
+verto_add_child(struct vertoEvCtx *ctx, enum vertoEvFlag flags,
+ vertoCallback callback, void *priv, pid_t pid);
/**
* Gets the private pointer of the vertoEv.
@@ -364,21 +350,6 @@ verto_get_private(const struct vertoEv *ev);
enum vertoEvType
verto_get_type(const struct vertoEv *ev);
-/**
- * Gets the priority of the vertoEv.
- *
- * @see verto_add_read()
- * @see verto_add_write()
- * @see verto_add_timeout()
- * @see verto_add_idle()
- * @see verto_add_signal()
- * @see verto_add_child()
- * @param ev The vertoEv
- * @return The vertoEv priority
- */
-enum vertoEvPriority
-verto_get_priority(const struct vertoEv *ev);
-
enum vertoEvFlag
verto_get_flags(const struct vertoEv *ev);
@@ -391,10 +362,7 @@ verto_get_flags(const struct vertoEv *ev);
* @return The file descriptor, or -1 if not a read/write event.
*/
int
-verto_get_io_fd(const struct vertoEv *ev);
-
-enum vertoEvIOFlag
-verto_get_io_flags(const struct vertoEv *ev);
+verto_get_fd(const struct vertoEv *ev);
/**
* Gets the interval associated with a timeout vertoEv.
diff --git a/tests/child.c b/tests/child.c
index e527375..02df32f 100644
--- a/tests/child.c
+++ b/tests/child.c
@@ -64,12 +64,12 @@ do_test(struct vertoEvCtx *ctx)
exit(EXITCODE);
}
- verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, exit_cb, NULL, 100);
+ verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, exit_cb, NULL, 100);
/* Persist makes no sense for children events */
- assert(!verto_add_child(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, cb, NULL, pid));
+ assert(!verto_add_child(ctx, VERTO_EV_FLAG_PERSIST, cb, NULL, pid));
- if (!verto_add_child(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, cb, NULL, pid)) {
+ if (!verto_add_child(ctx, VERTO_EV_FLAG_NONE, cb, NULL, pid)) {
printf("WARNING: Child not supported!\n");
usleep(100000);
waitpid(pid, &exitstatus, 0);
diff --git a/tests/idle.c b/tests/idle.c
index 1a508e4..aac2bda 100644
--- a/tests/idle.c
+++ b/tests/idle.c
@@ -57,7 +57,7 @@ void
cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
{
if (++callcount == 2) {
- verto_add_idle(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, cb, NULL);
+ verto_add_idle(ctx, VERTO_EV_FLAG_NONE, cb, NULL);
verto_del(ev);
}
}
@@ -66,8 +66,7 @@ int
do_test(struct vertoEvCtx *ctx)
{
callcount = 0;
- idle = verto_add_idle(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, cb, NULL);
- assert(verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE,
- exit_cb, NULL, idle ? 100 : 1));
+ idle = verto_add_idle(ctx, VERTO_EV_FLAG_PERSIST, cb, NULL);
+ assert(verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, exit_cb, NULL, idle ? 100 : 1));
return 0;
}
diff --git a/tests/read.c b/tests/read.c
index d769d65..aef7ba1 100644
--- a/tests/read.c
+++ b/tests/read.c
@@ -58,7 +58,7 @@ cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
int fd = 0;
ssize_t bytes = 0;
- fd = verto_get_io_fd(ev);
+ fd = verto_get_fd(ev);
assert(fd == fds[0]);
bytes = read(fd, buff, DATALEN);
@@ -71,6 +71,7 @@ cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
assert(bytes != DATALEN);
close(fd);
fds[0] = -1;
+ verto_del(ev);
verto_break(ctx);
}
}
@@ -83,8 +84,8 @@ do_test(struct vertoEvCtx *ctx)
fds[1] = -1;
assert(pipe(fds) == 0);
- assert(verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, timeout_cb, NULL, 1000));
- assert(verto_add_io(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, cb, NULL, fds[0], VERTO_EV_IO_FLAG_READ));
+ assert(verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, timeout_cb, NULL, 1000));
+ assert(verto_add_io(ctx, VERTO_EV_FLAG_PERSIST | VERTO_EV_FLAG_IO_READ, cb, NULL, fds[0]));
assert(write(fds[1], DATA, DATALEN) == DATALEN);
return 0;
}
diff --git a/tests/signal.c b/tests/signal.c
index 32bf8d5..a7e11ff 100644
--- a/tests/signal.c
+++ b/tests/signal.c
@@ -64,12 +64,11 @@ do_test(struct vertoEvCtx *ctx)
pid_t pid = 0;
count = 0;
- if (!verto_add_signal(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, cb, NULL, SIGUSR1)) {
+ if (!verto_add_signal(ctx, VERTO_EV_FLAG_PERSIST, cb, NULL, SIGUSR1)) {
printf("WARNING: Signal not supported!\n");
count = 2;
} else {
- verto_add_signal(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE,
- VERTO_SIG_IGN, NULL, SIGUSR2);
+ verto_add_signal(ctx, VERTO_EV_FLAG_NONE, VERTO_SIG_IGN, NULL, SIGUSR2);
pid = fork();
if (pid < 0)
@@ -85,8 +84,7 @@ do_test(struct vertoEvCtx *ctx)
}
}
- verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE,
- exit_cb, (void *) (uintptr_t) pid, 100);
+ verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, exit_cb, (void *) (uintptr_t) pid, 100);
return 0;
}
diff --git a/tests/timeout.c b/tests/timeout.c
index 086ee5e..0dc4ffd 100644
--- a/tests/timeout.c
+++ b/tests/timeout.c
@@ -62,9 +62,9 @@ cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
{
assert(elapsed(SLEEP, SLEEP*2));
if (++callcount == 3)
- assert(verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, exit_cb, NULL, SLEEP*2));
+ assert(verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, exit_cb, NULL, SLEEP*2));
else if (callcount == 2) {
- assert(verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, cb, NULL, SLEEP));
+ assert(verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, cb, NULL, SLEEP));
verto_del(ev);
}
}
@@ -75,6 +75,6 @@ do_test(struct vertoEvCtx *ctx)
callcount = 0;
assert(gettimeofday(&starttime, NULL) == 0);
- assert(verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, cb, NULL, SLEEP));
+ assert(verto_add_timeout(ctx, VERTO_EV_FLAG_PERSIST, cb, NULL, SLEEP));
return 0;
}
diff --git a/tests/write.c b/tests/write.c
index 350564b..e927478 100644
--- a/tests/write.c
+++ b/tests/write.c
@@ -57,26 +57,24 @@ error_cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
int fd = 0;
/* When we get here, the fd should be closed, so an error should occur */
- fd = verto_get_io_fd(ev);
+ fd = verto_get_fd(ev);
assert(write(fd, DATA, DATALEN) != DATALEN);
- verto_del(ev);
- verto_break(ctx);
close(fd);
fds[1] = -1;
+ verto_break(ctx);
}
static void
read_cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
{
unsigned char buff[DATALEN];
- int fd = verto_get_io_fd(ev);
+ int fd = verto_get_fd(ev);
assert(read(fd, buff, DATALEN) == DATALEN);
close(fd);
fds[0] = -1;
- verto_del(ev); /* We don't want this callback called because of close() */
- assert(verto_add_io(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, error_cb, NULL, fds[1], VERTO_EV_IO_FLAG_WRITE));
+ assert(verto_add_io(ctx, VERTO_EV_FLAG_IO_WRITE, error_cb, NULL, fds[1]));
}
static void
@@ -84,11 +82,10 @@ write_cb(struct vertoEvCtx *ctx, struct vertoEv *ev)
{
int fd = 0;
- fd = verto_get_io_fd(ev);
+ fd = verto_get_fd(ev);
assert(write(fd, DATA, DATALEN) == DATALEN);
- verto_del(ev);
- assert(verto_add_io(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, read_cb, NULL, fds[0], VERTO_EV_IO_FLAG_READ));
+ assert(verto_add_io(ctx, VERTO_EV_FLAG_IO_READ, read_cb, NULL, fds[0]));
}
int
@@ -98,11 +95,11 @@ do_test(struct vertoEvCtx *ctx)
fds[0] = -1;
fds[1] = -1;
- if (!verto_add_signal(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, VERTO_SIG_IGN, NULL, SIGPIPE))
+ if (!verto_add_signal(ctx, VERTO_EV_FLAG_NONE, VERTO_SIG_IGN, NULL, SIGPIPE))
signal(SIGPIPE, SIG_IGN);
assert(pipe(fds) == 0);
- assert(verto_add_timeout(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_NONE, timeout_cb, NULL, 1000));
- assert(verto_add_io(ctx, VERTO_EV_PRIORITY_DEFAULT, VERTO_EV_FLAG_PERSIST, write_cb, NULL, fds[1], VERTO_EV_IO_FLAG_WRITE));
+ assert(verto_add_timeout(ctx, VERTO_EV_FLAG_NONE, timeout_cb, NULL, 1000));
+ assert(verto_add_io(ctx, VERTO_EV_FLAG_IO_WRITE, write_cb, NULL, fds[1]));
return 0;
}