The system call epoll_wait() waits for events on the file descriptors associated with the given epoll instance: #include <sys/epoll.h> int epoll_wait (int epfd, 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 EFAULT EINTR EINVAL 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; events = malloc (sizeof (struct epoll_event) * MAX_EVENTS); nr_events = epoll_wait (epfd, events, MAX_EVENTS, -1); for (i = 0; i < nr_events; i++) { /* free (events); We will cover the functionsmalloc()andfree()in Chapter 8.
blog comments powered by Disqus |
|
|
|
|
|
|
|