/* do a single event loop using the events defined in ev */ static int std_event_loop_once(struct tevent_context *ev, const char *location) { struct std_event_context *std_ev = talloc_get_type(ev->additional_data, struct std_event_context); struct timeval tval; if (ev->signal_events && tevent_common_check_signal(ev)) { return 0; } if (ev->immediate_events && tevent_common_loop_immediate(ev)) { return 0; } tval = tevent_common_loop_timer_delay(ev); if (tevent_timeval_is_zero(&tval)) { return 0; } epoll_check_reopen(std_ev); if (epoll_event_loop(std_ev, &tval) == 0) { return 0; } return std_event_loop_select(std_ev, &tval); }
/* add a fd based event return NULL on failure (memory allocation error) */ static struct tevent_fd *std_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, int fd, uint16_t flags, tevent_fd_handler_t handler, void *private_data, const char *handler_name, const char *location) { struct std_event_context *std_ev = talloc_get_type(ev->additional_data, struct std_event_context); struct tevent_fd *fde; epoll_check_reopen(std_ev); fde = tevent_common_add_fd(ev, mem_ctx, fd, flags, handler, private_data, handler_name, location); if (!fde) return NULL; if ((std_ev->maxfd != EVENT_INVALID_MAXFD) && (fde->fd > std_ev->maxfd)) { std_ev->maxfd = fde->fd; } talloc_set_destructor(fde, std_event_fd_destructor); epoll_add_event(std_ev, fde); return fde; }
/* set the fd event flags */ static void std_event_set_fd_flags(struct tevent_fd *fde, uint16_t flags) { struct tevent_context *ev; struct std_event_context *std_ev; if (fde->flags == flags) return; ev = fde->event_ctx; std_ev = talloc_get_type(ev->additional_data, struct std_event_context); fde->flags = flags; epoll_check_reopen(std_ev); epoll_change_event(std_ev, fde); }
/* destroy an fd_event */ static int epoll_event_fd_destructor(struct tevent_fd *fde) { struct tevent_context *ev = fde->event_ctx; struct epoll_event_context *epoll_ev = NULL; if (ev) { epoll_ev = talloc_get_type(ev->additional_data, struct epoll_event_context); epoll_check_reopen(epoll_ev); epoll_del_event(epoll_ev, fde); } return tevent_common_fd_destructor(fde); }
/* destroy an fd_event */ static int std_event_fd_destructor(struct tevent_fd *fde) { struct tevent_context *ev = fde->event_ctx; struct std_event_context *std_ev = NULL; if (ev) { std_ev = talloc_get_type(ev->additional_data, struct std_event_context); epoll_check_reopen(std_ev); if (std_ev->maxfd == fde->fd) { std_ev->maxfd = EVENT_INVALID_MAXFD; } epoll_del_event(std_ev, fde); } return tevent_common_fd_destructor(fde); }
/* add a fd based event return NULL on failure (memory allocation error) */ static struct tevent_fd *epoll_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, int fd, uint16_t flags, tevent_fd_handler_t handler, void *private_data, const char *handler_name, const char *location) { struct epoll_event_context *epoll_ev = talloc_get_type(ev->additional_data, struct epoll_event_context); struct tevent_fd *fde; epoll_check_reopen(epoll_ev); fde = tevent_common_add_fd(ev, mem_ctx, fd, flags, handler, private_data, handler_name, location); if (!fde) return NULL; talloc_set_destructor(fde, epoll_event_fd_destructor); epoll_add_event(epoll_ev, fde); return fde; }