TODO s3:lib/events: add support for TEVENT_FD_ERROR
authorStefan Metzmacher <metze@samba.org>
Wed, 13 Jul 2011 08:05:32 +0000 (10:05 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Jul 2011 07:02:11 +0000 (09:02 +0200)
metze

source3/lib/events.c

index b0d3ce53626dede0caa6650574732d44ea8a880a..a88af9826151bb75b19f4eb0c0aadaed74dcdd04 100644 (file)
@@ -59,7 +59,7 @@ static void count_fds(struct tevent_context *ev,
        int max_fd = 0;
 
        for (fde = ev->fd_events; fde != NULL; fde = fde->next) {
-               if (fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) {
+               if (fde->flags != 0) {
                        num_fds += 1;
                        if (fde->fd > max_fd) {
                                max_fd = fde->fd;
@@ -131,7 +131,7 @@ bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
        for (fde = ev->fd_events; fde; fde = fde->next) {
                struct pollfd *pfd;
 
-               if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) == 0) {
+               if (fde->flags == 0) {
                        continue;
                }
 
@@ -151,10 +151,14 @@ bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
 
                pfd->fd = fde->fd;
 
-               if (fde->flags & EVENT_FD_READ) {
-                       pfd->events |= (POLLIN|POLLHUP);
+               /*
+                * we do not need to specify POLLERR | POLLHUP
+                * they are always reported.
+                */
+               if (fde->flags & TEVENT_FD_READ) {
+                       pfd->events |= POLLIN;
                }
-               if (fde->flags & EVENT_FD_WRITE) {
+               if (fde->flags & TEVENT_FD_WRITE) {
                        pfd->events |= POLLOUT;
                }
        }
@@ -264,18 +268,23 @@ bool run_events_poll(struct tevent_context *ev, int pollrtn,
                           and remove the writable flag, as we only
                           report errors when waiting for read events
                           to match the select behavior. */
-                       if (!(fde->flags & EVENT_FD_READ)) {
-                               EVENT_FD_NOT_WRITEABLE(fde);
+                       if ((fde->flags & ~TEVENT_FD_WRITE) == 0) {
+                               TEVENT_FD_NOT_WRITEABLE(fde);
                                continue;
                        }
-                       flags |= EVENT_FD_READ;
+                       if (fde->flags & TEVENT_FD_ERROR) {
+                               flags |= TEVENT_FD_ERROR;
+                       }
+                       if (fde->flags & TEVENT_FD_READ) {
+                               flags |= TEVENT_FD_READ;
+                       }
                }
 
                if (pfd->revents & POLLIN) {
-                       flags |= EVENT_FD_READ;
+                       flags |= TEVENT_FD_READ;
                }
                if (pfd->revents & POLLOUT) {
-                       flags |= EVENT_FD_WRITE;
+                       flags |= TEVENT_FD_WRITE;
                }
                if (flags & fde->flags) {
                        DLIST_DEMOTE(ev->fd_events, fde, struct tevent_fd);