eloop: allow flushing an fd

Sometimes one wants to remove all pending events for an fd. The new
ev_eloop_flush_fd() call allows this in a safe way.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-05-05 17:13:42 +02:00
parent 335182556c
commit f7b398a34a
2 changed files with 14 additions and 0 deletions

View File

@ -805,6 +805,19 @@ void ev_eloop_unref(struct ev_eloop *loop)
free(loop);
}
void ev_eloop_flush_fd(struct ev_eloop *loop, struct ev_fd *fd)
{
int i;
if (!loop || !fd)
return;
for (i = 0; i < loop->cur_fds_cnt; ++i) {
if (loop->cur_fds[i].data.ptr == fd)
loop->cur_fds[i].data.ptr = NULL;
}
}
int ev_eloop_dispatch(struct ev_eloop *loop, int timeout)
{
struct epoll_event ep[32];

View File

@ -62,6 +62,7 @@ int ev_eloop_new(struct ev_eloop **out);
void ev_eloop_ref(struct ev_eloop *loop);
void ev_eloop_unref(struct ev_eloop *loop);
void ev_eloop_flush_fd(struct ev_eloop *loop, struct ev_fd *fd);
int ev_eloop_dispatch(struct ev_eloop *loop, int timeout);
int ev_eloop_run(struct ev_eloop *loop, int timeout);
void ev_eloop_exit(struct ev_eloop *loop);