]> granicus.if.org Git - libevent/commitdiff
make kqueue work for callbacks that use both read and write events
authorNiels Provos <provos@gmail.com>
Tue, 11 Jun 2002 18:38:37 +0000 (18:38 +0000)
committerNiels Provos <provos@gmail.com>
Tue, 11 Jun 2002 18:38:37 +0000 (18:38 +0000)
simultaneously

svn:r26

event.c
kqueue.c

diff --git a/event.c b/event.c
index 4802f3aaa76209d78d2636028963837ce10c1ab8..4d5d6af74a72962a64cac7984d4eb8eeebab24a7 100644 (file)
--- a/event.c
+++ b/event.c
@@ -343,6 +343,12 @@ event_del(struct event *ev)
 void
 event_active(struct event *ev, int res, short ncalls)
 {
+       /* We get different kinds of events, add them together */
+       if (ev->ev_flags & EVLIST_ACTIVE) {
+               ev->ev_res |= res;
+               return;
+       }
+
        ev->ev_res = res;
        ev->ev_ncalls = ncalls;
        ev->ev_pncalls = NULL;
index 9daafa7ee88a9760ff6551e3a9011f34060417ba..38960dec8519420d23a978bd210e93cf75b50f70 100644 (file)
--- a/kqueue.c
+++ b/kqueue.c
@@ -218,16 +218,37 @@ kq_dispatch(void *arg, struct timeval *tv)
                        which |= EV_WRITE;
                } else if (events[i].filter == EVFILT_SIGNAL) {
                        which |= EV_SIGNAL;
-               }
+               } else
+                       events[i].filter = 0;
+
+               if (!which)
+                       continue;
+
+               event_active(ev, which,
+                   ev->ev_events & EV_SIGNAL ? events[i].data : 1);
+       }
+
+       for (i = 0; i < res; i++) {
+               /* XXX */
+               int ncalls, res;
 
-               if (which) {
-                       if (!(ev->ev_events & EV_PERSIST)) {
-                               ev->ev_flags &= ~EVLIST_X_KQINKERNEL;
-                               event_del(ev);
-                       }
-                       event_active(ev, which,
-                           ev->ev_events & EV_SIGNAL ? events[i].data : 1);
+               if (events[i].flags & EV_ERROR || events[i].filter == NULL)
+                       continue;
+
+               ev = events[i].udata;
+               if (ev->ev_events & EV_PERSIST)
+                       continue;
+
+               ncalls = 0;
+               if (ev->ev_flags & EVLIST_ACTIVE) {
+                       ncalls = ev->ev_ncalls;
+                       res = ev->ev_res;
                }
+               ev->ev_flags &= ~EVLIST_X_KQINKERNEL;
+               event_del(ev);
+
+               if (ncalls)
+                       event_active(ev, res, ncalls);
        }
 
        return (0);