Minimize epoll_ctl calls by using changelist The logic here is a little complex, since epoll_add must used called exactly when no events were previously set, epoll_mod must be used when any events were previously set, and epoll_del only called when the removing all events.