epoll: Fire existing events during EPOLL_CTL_ADD
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Feb 2017 19:08:38 +0000 (14:08 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 2 Mar 2017 18:00:09 +0000 (13:00 -0500)
commite2bc7fe368ea7b68f84c66e9ecfe23ae284f0575
treeb99210b67dc8ce7dc972f58146e48e00e5470979
parent76f8e22473981fe19de7cfa8317d70881f720810
epoll: Fire existing events during EPOLL_CTL_ADD

On Linux, if you ask for an edge-triggered epoll, the kernel happens to
send you an event based on the current status when you sign up,
level-triggered-style.

Specifically, this will return with an EPOLLOUT event:
- epoll_create()
- socket(SOCK_DGRAM)
- epoll_ctl_add(EPOLLOUT | EPOLLET)
- epoll_wait()

Even though you're only supposed to epoll_wait() on an edge-triggered event
*after* you've attempted I/O and got EAGAIN.

However, our epoll() tries to act like Linux's, and some buggy programs
may expect Linux's epoll's behavior.

Note that this change may result in spurious notifications.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/iplib/epoll.c