# HG changeset patch # User Olaf Wintermann # Date 1606992469 -3600 # Node ID 81f202caea5b5a22a594b0fa140b7bb70f0ee557 # Parent 533f9097d71237cfd09c74fbd83b774656b77112 add ev_remove_poll kqueue implementation diff -r 533f9097d712 -r 81f202caea5b src/server/daemon/event_bsd.c --- a/src/server/daemon/event_bsd.c Thu Dec 03 11:24:51 2020 +0100 +++ b/src/server/daemon/event_bsd.c Thu Dec 03 11:47:49 2020 +0100 @@ -72,7 +72,7 @@ for(;;) { // wait for events - int nev = kevent(ev->kqueue, changes, numchanges, events, 64, &timeout); + int nev = kevent(ev->kqueue, changes, numchanges, events, 64, &timeout); if(nev == -1) { // TODO: check for error perror("kevent"); @@ -92,8 +92,7 @@ int saved_ev = event->events; if(!event->fn(ev, event)) { // ret 0 => remove event - kev_flag = EV_DELETE; - + kev_flag = EV_DELETE; if(event->finish) { event->finish(ev, event); } @@ -140,8 +139,13 @@ } int ev_remove_poll(EventHandler *h, int fd) { - // TODO: - return 0; + struct kevent kev; + EV_SET(&kev, fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); + int r1 = kevent(h->kqueue, &kev, 1, NULL, 0, NULL); + EV_SET(&kev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); + int r2 = kevent(h->kqueue, &kev, 1, NULL, 0, NULL); + // in caase r1 or r2 was successful, we return 0 (no error) + return r1 != -1 || r2 != -1 ? 0 : 1; } int event_send(EventHandler *h, Event *event) {