The system call epoll_wait() waits for events on the file descriptors associated with the given epoll instance:
int epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout);
A call to epoll_wait() waits up to timeoutmilliseconds for events on the files associated with the epoll instanceepfd. Upon success,eventspoints to memory containingepoll_eventstructures describing each event, up to a maximum ofmaxeventsevents. The return value is the number of events, or-1on error, in which caseerrnois set to one of the following:
EBADF epfdis not a valid file descriptor.
EFAULT The process does not have write access to the memory pointed at byevents.
EINTR The system call was interrupted by a signal before it could complete.
EINVAL epfd is not a valid epoll instance, ormaxeventsis equal to or less than0.
Iftimeoutis0, the call returns immediately, even if no events are available, in which case the call will return0. If thetimeoutis-1, the call will not return until an event is available.
When the call returns, theeventsfield of theepoll_eventstructure describes the events that occurred. Thedata field contains whatever the user set it to before invocation ofepoll_ctl().
A fullepoll_wait()example looks like this:
#define MAX_EVENTS 64
struct epoll_event *events; int nr_events, i, epfd;