eloop: allow edge-triggered operation
A new EV_ET flag allows ev_fd sources to operate in edge-triggered instead of level-triggered mode. See epoll(7) for more information. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
e8c439c805
commit
ae97bbf7e3
@ -1144,6 +1144,8 @@ static int fd_epoll_add(struct ev_fd *fd)
|
||||
ep.events |= EPOLLIN;
|
||||
if (fd->mask & EV_WRITEABLE)
|
||||
ep.events |= EPOLLOUT;
|
||||
if (fd->mask & EV_ET)
|
||||
ep.events |= EPOLLET;
|
||||
ep.data.ptr = fd;
|
||||
|
||||
ret = epoll_ctl(fd->loop->efd, EPOLL_CTL_ADD, fd->fd, &ep);
|
||||
@ -1182,6 +1184,8 @@ static int fd_epoll_update(struct ev_fd *fd)
|
||||
ep.events |= EPOLLIN;
|
||||
if (fd->mask & EV_WRITEABLE)
|
||||
ep.events |= EPOLLOUT;
|
||||
if (fd->mask & EV_ET)
|
||||
ep.events |= EPOLLET;
|
||||
ep.data.ptr = fd;
|
||||
|
||||
ret = epoll_ctl(fd->loop->efd, EPOLL_CTL_MOD, fd->fd, &ep);
|
||||
@ -1297,7 +1301,7 @@ int ev_fd_update(struct ev_fd *fd, int mask)
|
||||
|
||||
if (!fd)
|
||||
return -EINVAL;
|
||||
if (fd->mask == mask)
|
||||
if (fd->mask == mask && !(mask & EV_ET))
|
||||
return 0;
|
||||
|
||||
omask = fd->mask;
|
||||
|
@ -129,17 +129,20 @@ typedef void (*ev_idle_cb) (struct ev_eloop *eloop, void *unused, void *data);
|
||||
* @EV_WRITEABLE: file-desciprotr is writeable
|
||||
* @EV_HUP: Hang-up on file-descriptor
|
||||
* @EV_ERR: I/O error on file-descriptor
|
||||
* @EV_ET: Edge-triggered mode
|
||||
*
|
||||
* These flags are used for events on file-descriptors. You can combine them
|
||||
* with binary-operators like @EV_READABLE | @EV_WRITEABLE.
|
||||
* @EV_HUP and @EV_ERR are always raised for file-descriptors, even if not
|
||||
* requested explicitly.
|
||||
* @EV_ET enables edge-triggered mode for the operation
|
||||
*/
|
||||
enum ev_eloop_flags {
|
||||
EV_READABLE = 0x01,
|
||||
EV_WRITEABLE = 0x02,
|
||||
EV_HUP = 0x04,
|
||||
EV_ERR = 0x08,
|
||||
EV_ET = 0x10,
|
||||
};
|
||||
|
||||
int ev_eloop_new(struct ev_eloop **out, ev_log_t log);
|
||||
|
Loading…
x
Reference in New Issue
Block a user