tevent: unify handling of HAS_EVENT and REPORT_ERROR in epoll_{add,mod,del}_event()
authorStefan Metzmacher <metze@samba.org>
Wed, 20 Feb 2013 16:38:10 +0000 (17:38 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 26 Feb 2013 15:43:57 +0000 (16:43 +0100)
epoll_{add,mod,del}_event() are only called via epoll_update_event()
and epoll_update_event() should not remove REPORT_ERROR itself.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/tevent/tevent_epoll.c

index 760ea22c48f9e734297966311468d00e74931036..e04a0ab253b4f5934f4a7b494ba79792aa67feba 100644 (file)
@@ -271,11 +271,9 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct tevent_
        struct epoll_event event;
        int ret;
 
+       fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
        fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
 
-       /* if we don't want events yet, don't add an epoll_event */
-       if (fde->flags == 0) return;
-
        ZERO_STRUCT(event);
        event.events = epoll_map_flags(fde->flags);
        event.data.ptr = fde;
@@ -284,8 +282,8 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct tevent_
                epoll_panic(epoll_ev, "EPOLL_CTL_ADD failed", false);
                return;
        }
-       fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
 
+       fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
        /* only if we want to read we want to tell the event handler about errors */
        if (fde->flags & TEVENT_FD_READ) {
                fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
@@ -300,18 +298,15 @@ static void epoll_del_event(struct epoll_event_context *epoll_ev, struct tevent_
        struct epoll_event event;
        int ret;
 
+       fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
        fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
 
-       /* if there's no epoll_event, we don't need to delete it */
-       if (!(fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT)) return;
-
        ZERO_STRUCT(event);
        ret = epoll_ctl(epoll_ev->epoll_fd, EPOLL_CTL_DEL, fde->fd, &event);
        if (ret != 0) {
                epoll_panic(epoll_ev, "EPOLL_CTL_DEL failed", false);
                return;
        }
-       fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
 }
 
 /*
@@ -322,6 +317,7 @@ static void epoll_mod_event(struct epoll_event_context *epoll_ev, struct tevent_
        struct epoll_event event;
        int ret;
 
+       fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
        fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
 
        ZERO_STRUCT(event);
@@ -333,6 +329,7 @@ static void epoll_mod_event(struct epoll_event_context *epoll_ev, struct tevent_
                return;
        }
 
+       fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
        /* only if we want to read we want to tell the event handler about errors */
        if (fde->flags & TEVENT_FD_READ) {
                fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
@@ -345,8 +342,6 @@ static void epoll_update_event(struct epoll_event_context *epoll_ev, struct teve
        bool want_read = (fde->flags & TEVENT_FD_READ);
        bool want_write= (fde->flags & TEVENT_FD_WRITE);
 
-       fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
-
        /* there's already an event */
        if (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT) {
                if (want_read || (want_write && !got_error)) {