Thu, 03 Dec 2020 11:47:49 +0100
add ev_remove_poll kqueue implementation
src/server/daemon/event_bsd.c | file | annotate | diff | comparison | revisions |
--- 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) {