From: macrule <562520+macrule@users.noreply.github.com> Date: Wed, 29 Nov 2017 17:18:53 +0000 (+0100) Subject: tvhpoll: Fixed tvhpoll_add kqueue implementation. X-Git-Tag: v4.2.5~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d1d2d8ff779f19cb14ac3df274444f30f22e03e;p=thirdparty%2Ftvheadend.git tvhpoll: Fixed tvhpoll_add kqueue implementation. The semantics of tvhpoll_add() in the epoll implementation is to set exactly the specified filters, and not add to any previously added ones. The kqueue implementation only added filters, and never removed those that were not set anymore. This caused busy-polling in satip_frontend on FreeBSD and Darwin, because tvhpoll_wait() always returned immediately. This happened because the receiving socket was always ready to accept data for writing. The following recv() call was called repeatedly without any delay and caused high CPU utilization. --- diff --git a/src/tvhpoll.c b/src/tvhpoll.c index 64c5aa0be..05da0c82e 100644 --- a/src/tvhpoll.c +++ b/src/tvhpoll.c @@ -131,6 +131,9 @@ int tvhpoll_add evs[i].fd, rc); return -1; } + } else { + EV_SET(tp->ev+i, evs[i].fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); + kevent(tp->fd, tp->ev+i, 1, NULL, 0, NULL); } if (evs[i].events & TVHPOLL_IN){ EV_SET(tp->ev+i, evs[i].fd, EVFILT_READ, EV_ADD, 0, 0, (intptr_t*)evs[i].data.u64); @@ -139,6 +142,9 @@ int tvhpoll_add tvherror(LS_TVHPOLL, "failed to add kqueue READ filter [%d|%d]", evs[i].fd, rc); return -1; } + } else { + EV_SET(tp->ev+i, evs[i].fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); + kevent(tp->fd, tp->ev+i, 1, NULL, 0, NULL); } } return 0;