From 047cc44c8358a154dde22f0a1725c4d81836cf60 Mon Sep 17 00:00:00 2001 From: martijn81 Date: Sat, 6 May 2017 13:53:38 +0200 Subject: [PATCH] Add edgetrigger and oneshot event types --- io.c | 6 ++++++ private.h | 3 ++- uev.c | 18 ++++++++++++++++++ uev.h | 3 +++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/io.c b/io.c index 3fd0877..690d92b 100644 --- a/io.c +++ b/io.c @@ -60,6 +60,12 @@ int uev_io_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int e */ int uev_io_set(uev_t *w, int fd, int events) { + + if( events & UEV_ONESHOT + && 1 == w->active ) { + return uev_watcher_rearm(w); + } + /* Ignore any errors, only to clean up anything lingering ... */ uev_io_stop(w); diff --git a/private.h b/private.h index f37d418..7b4150c 100644 --- a/private.h +++ b/private.h @@ -38,7 +38,7 @@ typedef enum { } uev_type_t; /* Event mask, used internally only. */ -#define UEV_EVENT_MASK (UEV_READ | UEV_WRITE | UEV_PRI | UEV_HUP) +#define UEV_EVENT_MASK (UEV_READ | UEV_WRITE | UEV_PRI | UEV_HUP | UEV_RDHUP | UEV_ET | UEV_ONESHOT) /* Main libuEv context type */ typedef struct { @@ -87,6 +87,7 @@ int uev_watcher_init (uev_ctx_t *ctx, struct uev *w, uev_type_t type, int uev_watcher_start (struct uev *w); int uev_watcher_stop (struct uev *w); int uev_watcher_active(struct uev *w); +int uev_watcher_rearm (struct uev *w); #endif /* LIBUEV_PRIVATE_H_ */ diff --git a/uev.c b/uev.c index 0ade541..3ecdd9d 100644 --- a/uev.c +++ b/uev.c @@ -133,6 +133,24 @@ int uev_watcher_active(uev_t *w) return w->active; } +/* Private to libuEv, do not use directly! */ +int uev_watcher_rearm(uev_t *w) +{ + struct epoll_event ev; + + if (!w || w->fd < 0) { + errno = EINVAL; + return -1; + } + + ev.events = w->events | EPOLLRDHUP; + ev.data.ptr = w; + if (epoll_ctl(w->ctx->fd, EPOLL_CTL_MOD, w->fd, &ev) < 0) + return -1; + + return 0; +} + /** * Create an event loop context * @param ctx Pointer to an uev_ctx_t context to be initialized diff --git a/uev.h b/uev.h index 4b5b3e4..bd6ce10 100644 --- a/uev.h +++ b/uev.h @@ -36,6 +36,9 @@ #define UEV_WRITE EPOLLOUT #define UEV_PRI EPOLLPRI #define UEV_HUP EPOLLHUP +#define UEV_RDHUP EPOLLRDHUP +#define UEV_ET EPOLLET +#define UEV_ONESHOT EPOLLONESHOT /* Run flags */ #define UEV_ONCE 1