tevent: Fix multiple handler on the same fd bug in the tevent select backend.
authorJeremy Allison <jra@samba.org>
Wed, 27 Feb 2013 18:18:44 +0000 (10:18 -0800)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Mar 2013 17:51:52 +0000 (18:51 +0100)
When we're deciding what handlers to call in the select backend,
we didn't take into account the fact that the same fd may have
been added into the read FD_SET and the write FD_SET but with
different handlers.

We must match on both the file descriptor and the flags requested
before calling the handler.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/tevent/tevent_select.c

index ffb0d18c2e9f21cb737d782eb7b44ba6f8407229..24032631f8ab126b3aa8abd854a93d61805c0853 100644 (file)
@@ -210,8 +210,12 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
                for (fde = select_ev->ev->fd_events; fde; fde = fde->next) {
                        uint16_t flags = 0;
 
-                       if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ;
-                       if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE;
+                       if (FD_ISSET(fde->fd, &r_fds) && (fde->flags & TEVENT_FD_READ)) {
+                               flags |= TEVENT_FD_READ;
+                       }
+                       if (FD_ISSET(fde->fd, &w_fds) && (fde->flags & TEVENT_FD_WRITE)) {
+                               flags |= TEVENT_FD_WRITE;
+                       }
                        if (flags) {
                                fde->handler(select_ev->ev, fde, flags, fde->private_data);
                                break;