uloop: add back state tracking on mac os x, it seems to work reliably now (after the other fixes)

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2013-01-05 16:04:41 +01:00
parent f1735cd94e
commit b7930023ee

19
uloop.c
View file

@ -96,20 +96,30 @@ static int register_kevent(struct uloop_fd *fd, unsigned int flags)
struct kevent ev[2]; struct kevent ev[2];
int nev = 0; int nev = 0;
unsigned int fl = 0; unsigned int fl = 0;
unsigned int changed;
uint16_t kflags; uint16_t kflags;
if (flags & ULOOP_EDGE_DEFER) if (flags & ULOOP_EDGE_DEFER)
flags &= ~ULOOP_EDGE_TRIGGER; flags &= ~ULOOP_EDGE_TRIGGER;
kflags = get_flags(flags, ULOOP_READ); changed = flags ^ fd->flags;
EV_SET(&ev[nev++], fd->fd, EVFILT_READ, kflags, 0, 0, fd); if (changed & ULOOP_EDGE_TRIGGER)
changed |= flags;
kflags = get_flags(flags, ULOOP_WRITE); if (changed & ULOOP_READ) {
EV_SET(&ev[nev++], fd->fd, EVFILT_WRITE, kflags, 0, 0, fd); 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) if (!flags)
fl |= EV_DELETE; fl |= EV_DELETE;
fd->flags = flags;
if (kevent(poll_fd, ev, nev, NULL, fl, &timeout) == -1) if (kevent(poll_fd, ev, nev, NULL, fl, &timeout) == -1)
return -1; return -1;
@ -123,7 +133,6 @@ static int register_poll(struct uloop_fd *fd, unsigned int flags)
else else
flags &= ~ULOOP_EDGE_DEFER; flags &= ~ULOOP_EDGE_DEFER;
fd->flags = flags;
return register_kevent(fd, flags); return register_kevent(fd, flags);
} }