From 4057ef2e11df6f7065f9691d0f388aea56faae45 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Feb 2013 15:53:38 -0800 Subject: tevent: Add utility function epoll_handle_hup_or_err() We'll use this to handle the EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR and EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR flags with multiplexed events in the event loop. Signed-off-by: Jeremy Allison Reviewed-by: Stefan Metzmacher --- lib/tevent/tevent_epoll.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/tevent') diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index 3608d4b622..3e3ddf9d3f 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -586,6 +586,38 @@ static void epoll_update_event(struct epoll_event_context *epoll_ev, struct teve } } +/* + Cope with epoll returning EPOLLHUP|EPOLLERR on an event. + Return true if there's nothing else to do, false if + this event needs further handling. +*/ +static bool epoll_handle_hup_or_err(struct epoll_event_context *epoll_ev, + struct tevent_fd *fde) +{ + if (fde == NULL) { + /* Nothing to do if no event. */ + return true; + } + + fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR; + /* + * if we only wait for TEVENT_FD_WRITE, we should not tell the + * event handler about it, and remove the epoll_event, + * as we only report errors when waiting for read events, + * to match the select() behavior + */ + if (!(fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR)) { + /* + * Do the same as the poll backend and + * remove the writeable flag. + */ + fde->flags &= ~TEVENT_FD_WRITE; + return true; + } + /* This has TEVENT_FD_READ set, we're not finished. */ + return false; +} + /* event loop handling using epoll */ -- cgit