mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-09 16:21:13 +00:00
Add edgetrigger and oneshot event types
This commit is contained in:
1 parent
2c675519a3
commit
047cc44c83
4 files changed
+29
-1
No files matched your search
@@ -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)
|
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 ... */
|
/* Ignore any errors, only to clean up anything lingering ... */
|
||||||
uev_io_stop(w);
|
uev_io_stop(w);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ typedef enum {
|
|||||||
} uev_type_t;
|
} uev_type_t;
|
||||||
|
|
||||||
/* Event mask, used internally only. */
|
/* 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 */
|
/* Main libuEv context type */
|
||||||
typedef struct {
|
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_start (struct uev *w);
|
||||||
int uev_watcher_stop (struct uev *w);
|
int uev_watcher_stop (struct uev *w);
|
||||||
int uev_watcher_active(struct uev *w);
|
int uev_watcher_active(struct uev *w);
|
||||||
|
int uev_watcher_rearm (struct uev *w);
|
||||||
|
|
||||||
#endif /* LIBUEV_PRIVATE_H_ */
|
#endif /* LIBUEV_PRIVATE_H_ */
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,24 @@ int uev_watcher_active(uev_t *w)
|
|||||||
return w->active;
|
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
|
* Create an event loop context
|
||||||
* @param ctx Pointer to an uev_ctx_t context to be initialized
|
* @param ctx Pointer to an uev_ctx_t context to be initialized
|
||||||
|
|||||||
@@ -36,6 +36,9 @@
|
|||||||
#define UEV_WRITE EPOLLOUT
|
#define UEV_WRITE EPOLLOUT
|
||||||
#define UEV_PRI EPOLLPRI
|
#define UEV_PRI EPOLLPRI
|
||||||
#define UEV_HUP EPOLLHUP
|
#define UEV_HUP EPOLLHUP
|
||||||
|
#define UEV_RDHUP EPOLLRDHUP
|
||||||
|
#define UEV_ET EPOLLET
|
||||||
|
#define UEV_ONESHOT EPOLLONESHOT
|
||||||
|
|
||||||
/* Run flags */
|
/* Run flags */
|
||||||
#define UEV_ONCE 1
|
#define UEV_ONCE 1
|
||||||
|
|||||||
Reference in new issue
Block a user