tevent: Add utility function epoll_handle_hup_or_err()
authorJeremy Allison <jra@samba.org>
Thu, 14 Feb 2013 23:53:38 +0000 (15:53 -0800)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Mar 2013 18:54:50 +0000 (19:54 +0100)
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 <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/tevent/tevent_epoll.c

index 3608d4b6225ca52d2188bd96a2207a8a95a21682..3e3ddf9d3f3e488ab79a9c76f13adbeaf24fdc24 100644 (file)
@@ -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
 */