mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-08 16:14:38 +07:00
Add edgetrigger and oneshot event types
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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_ */
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user