uloop: add back state tracking on mac os x, it seems to work reliably now (after...
authorFelix Fietkau <nbd@openwrt.org>
Sat, 5 Jan 2013 15:04:41 +0000 (16:04 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 5 Jan 2013 15:04:55 +0000 (16:04 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uloop.c

diff --git a/uloop.c b/uloop.c
index 2d7b2c93406a498b359d28042ca1408dbe039271..ecf26ec185db87fadb0d2aa2cadacf6b1b4a0ae0 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -96,20 +96,30 @@ static int register_kevent(struct uloop_fd *fd, unsigned int flags)
        struct kevent ev[2];
        int nev = 0;
        unsigned int fl = 0;
+       unsigned int changed;
        uint16_t kflags;
 
        if (flags & ULOOP_EDGE_DEFER)
                flags &= ~ULOOP_EDGE_TRIGGER;
 
-       kflags = get_flags(flags, ULOOP_READ);
-       EV_SET(&ev[nev++], fd->fd, EVFILT_READ, kflags, 0, 0, fd);
+       changed = flags ^ fd->flags;
+       if (changed & ULOOP_EDGE_TRIGGER)
+               changed |= flags;
 
-       kflags = get_flags(flags, ULOOP_WRITE);
-       EV_SET(&ev[nev++], fd->fd, EVFILT_WRITE, kflags, 0, 0, fd);
+       if (changed & ULOOP_READ) {
+               kflags = get_flags(flags, ULOOP_READ);
+               EV_SET(&ev[nev++], fd->fd, EVFILT_READ, kflags, 0, 0, fd);
+       }
+
+       if (changed & ULOOP_WRITE) {
+               kflags = get_flags(flags, ULOOP_WRITE);
+               EV_SET(&ev[nev++], fd->fd, EVFILT_WRITE, kflags, 0, 0, fd);
+       }
 
        if (!flags)
                fl |= EV_DELETE;
 
+       fd->flags = flags;
        if (kevent(poll_fd, ev, nev, NULL, fl, &timeout) == -1)
                return -1;
 
@@ -123,7 +133,6 @@ static int register_poll(struct uloop_fd *fd, unsigned int flags)
        else
                flags &= ~ULOOP_EDGE_DEFER;
 
-       fd->flags = flags;
        return register_kevent(fd, flags);
 }