From 047cc44c8358a154dde22f0a1725c4d81836cf60 Mon Sep 17 00:00:00 2001 From: martijn81 Date: Sat, 6 May 2017 13:53:38 +0200 Subject: [PATCH 1/5] 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 From 92cfe557ca1b6b2ba6f7cee972e19fa0d49d9ed4 Mon Sep 17 00:00:00 2001 From: martijn81 Date: Sat, 6 May 2017 17:37:36 +0200 Subject: [PATCH 2/5] Minor changes --- io.c | 7 +++---- uev.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/io.c b/io.c index 690d92b..b9ebdf2 100644 --- a/io.c +++ b/io.c @@ -61,10 +61,9 @@ 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); - } + if( (events & UEV_ONESHOT) && w->active ) { + return uev_watcher_rearm(w); + } /* Ignore any errors, only to clean up anything lingering ... */ uev_io_stop(w); diff --git a/uev.h b/uev.h index bd6ce10..dbfd02f 100644 --- a/uev.h +++ b/uev.h @@ -37,7 +37,7 @@ #define UEV_PRI EPOLLPRI #define UEV_HUP EPOLLHUP #define UEV_RDHUP EPOLLRDHUP -#define UEV_ET EPOLLET +#define UEV_EDGE EPOLLET #define UEV_ONESHOT EPOLLONESHOT /* Run flags */ From e18d9806066d3671d0c402b6aa3662d9c322b4f7 Mon Sep 17 00:00:00 2001 From: martijn81 Date: Sat, 6 May 2017 17:41:28 +0200 Subject: [PATCH 3/5] Added some spaces. --- io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io.c b/io.c index b9ebdf2..297b8bd 100644 --- a/io.c +++ b/io.c @@ -61,8 +61,8 @@ 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) && w->active ) { - return uev_watcher_rearm(w); + if ((events & UEV_ONESHOT) && w->active) { + return uev_watcher_rearm(w); } /* Ignore any errors, only to clean up anything lingering ... */ From 6354b333168e16c2b06dba94b45126b1d1c16593 Mon Sep 17 00:00:00 2001 From: martijn81 Date: Sat, 6 May 2017 17:48:05 +0200 Subject: [PATCH 4/5] UEV_EVENT_MASK change --- private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private.h b/private.h index 7b4150c..7670213 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 | UEV_RDHUP | UEV_ET | UEV_ONESHOT) +#define UEV_EVENT_MASK (UEV_READ | UEV_WRITE | UEV_PRI | UEV_HUP | UEV_RDHUP | UEV_EDGE | UEV_ONESHOT) /* Main libuEv context type */ typedef struct { From 48fc8a38bcb723b2691ea21c8a222f49970cea1a Mon Sep 17 00:00:00 2001 From: martijn81 Date: Sat, 6 May 2017 18:00:07 +0200 Subject: [PATCH 5/5] indentation problem fixed. --- io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io.c b/io.c index 297b8bd..b660d4f 100644 --- a/io.c +++ b/io.c @@ -62,7 +62,7 @@ int uev_io_set(uev_t *w, int fd, int events) { if ((events & UEV_ONESHOT) && w->active) { - return uev_watcher_rearm(w); + return uev_watcher_rearm(w); } /* Ignore any errors, only to clean up anything lingering ... */