]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhpoll: Fixed tvhpoll_add kqueue implementation.
authormacrule <562520+macrule@users.noreply.github.com>
Wed, 29 Nov 2017 17:18:53 +0000 (18:18 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 10 Dec 2017 15:08:44 +0000 (16:08 +0100)
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.

src/tvhpoll.c

index 64c5aa0be9784b93506b26c5a34bd943aa502552..05da0c82e1b54f44b37ba2d90fa594719cddf772 100644 (file)
@@ -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;