Let's say I add a socket an epoll, waiting for both EPOLLIN and EPOLLOUT events, something like this:
struct epoll_event event;
event.events = EPOLLIN | EPOLLOUT;
epoll_ctl(epfd, EPOLL_CTL_ADD, socket, &event);
If the socket becomes readable and writeable, would I need to call epoll_wait()
twice to receive both events, or will it return one epoll_event
with both bitfields set? (Assuming epoll_wait()
is called with a maxevents
of 1.)
CodePudding user response:
The documentation of epoll_wait()
says:
The events field is a bit mask that indicates the events that have occurred for the corresponding open file description.
The plural "events" implies that multiple events can occur for the same descriptor.
I believe the maxevents
argument to epoll_wait()
actually specifies the maximum elements in the events
array -- if a single FD has multiple events occur, they're all in one element.
Note that if you use level-triggered events (the default), EPOLLOUT
will almost always be triggered immediately, since the socket is always ready to write unless you write so much that you fill the kernel's socket buffer.