0

The epoll_wait prototype is:

int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);

The select prototype is:

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

Note that epoll_wait has one special fd as the first argument and the other file descriptors are in the "events" array.

Note that select does not single out any fd; all them them are identified in the *fds arguments.

Why did epoll_wait choose to have one file descriptor as "special", rather than making it just another element in the events array.

The context of this question is I am studying epoll trying to decide if I should recode existing programs using select.

One of the programs listens to two network sockets at the same time. How would I decide which one gets the honor of being "epfd"?

Be Kind To New Users
  • 9,672
  • 13
  • 78
  • 125
  • You need to read the [man pages for `epoll(7)`](http://man7.org/linux/man-pages/man7/epoll.7.html). `epfd` is not just "one special file descriptor" - it is a file descriptor referring to an epoll instance, created by [`epoll_create(2)`](http://man7.org/linux/man-pages/man2/epoll_create.2.html). Personally, I would recommend `select`, due to its portability. Otherwise, the question isn't so much about prototypes (they're different APIs, period) but rather just epoll vs select. – Jonathon Reinhart May 20 '14 at 04:20
  • http://stackoverflow.com/questions/6303507/epoll-vs-select – Jonathon Reinhart May 20 '14 at 04:21
  • `the other file descriptors are in the "events" array.` nope, the events array does not have *all* the other descriptors. It only contains what is ready (returned from the function) and only as many as the program has allocated. Which is typically a lot ess than the entire set. – n. m. could be an AI May 20 '14 at 09:31

0 Answers0