Edge-triggered epoll

2019-08-04

What a shame it took me 12 years to finally realize LT (level-triggered) is not necessarily easier to use than ET (edge-triggered).

It was in 2007 that I first knew of ET (and of epoll), and I have since believed it was more difficult to code ET correctly.

I also believed that you always save work by using LT (when the performance gain from ET is not important) — until yesterday, when I was actually writing some epoll code (instead of relying on some framework like libuv).

I completely overlooked the sentence in man 7 epoll:

When used as an edge-triggered interface, for performance reasons, it is possible to add the file descriptor inside the epoll interface (EPOLL_CTL_ADD) once by specifying (EPOLLIN|EPOLLOUT).  This allows you to avoid continuously switching between EPOLLIN and EPOLLOUT calling epoll_ctl(2) with EPOLL_CTL_MOD.

Yes, ET does not just add complexity, but also saves some cubersome work.