Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-01-04 06:17:51 +0400
committerFelix Fietkau <nbd@openwrt.org>2013-01-04 06:18:42 +0400
commit17f4e41ecb80f70c14493b4518e6eabec9faff7b (patch)
treeb202846552dd39b6b39de953929c75e3381de47a /uloop.c
parentc2916d7bcca129152fbbbbedcd9990706df8760a (diff)
uloop: improve edge trigger reliability on mac os x
Sometimes after re-arming a fd, an initial event for reads is not generated, even though there is data pending. Work around this by making the trigger level-triggered first, then switching to edge trigger after processing the first event. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'uloop.c')
-rw-r--r--uloop.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/uloop.c b/uloop.c
index bf17219..2d7b2c9 100644
--- a/uloop.c
+++ b/uloop.c
@@ -90,7 +90,7 @@ static uint16_t get_flags(unsigned int flags, unsigned int mask)
static struct kevent events[ULOOP_MAX_EVENTS];
-static int register_poll(struct uloop_fd *fd, unsigned int flags)
+static int register_kevent(struct uloop_fd *fd, unsigned int flags)
{
struct timespec timeout = { 0, 0 };
struct kevent ev[2];
@@ -98,6 +98,9 @@ static int register_poll(struct uloop_fd *fd, unsigned int flags)
unsigned int fl = 0;
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);
@@ -107,12 +110,23 @@ static int register_poll(struct uloop_fd *fd, unsigned int flags)
if (!flags)
fl |= EV_DELETE;
- if (nev && (kevent(poll_fd, ev, nev, NULL, fl, &timeout) == -1))
+ if (kevent(poll_fd, ev, nev, NULL, fl, &timeout) == -1)
return -1;
return 0;
}
+static int register_poll(struct uloop_fd *fd, unsigned int flags)
+{
+ if (flags & ULOOP_EDGE_TRIGGER)
+ flags |= ULOOP_EDGE_DEFER;
+ else
+ flags &= ~ULOOP_EDGE_DEFER;
+
+ fd->flags = flags;
+ return register_kevent(fd, flags);
+}
+
int uloop_fd_delete(struct uloop_fd *sock)
{
int i;
@@ -166,6 +180,10 @@ static void uloop_run_events(int timeout)
cur_fd = n;
cur_nfds = nfds;
u->cb(u, ev);
+ if (u->flags & ULOOP_EDGE_DEFER) {
+ u->flags &= ~ULOOP_EDGE_DEFER;
+ register_kevent(u, u->flags);
+ }
}
}
cur_nfds = 0;