Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the order in which File Descriptors in epoll are returned?

Tags:

c

linux

epoll

Let's say I have set a set of file descriptors, say 8, 9, 10, 11, 12 in the order specified and do an epoll_wait() for data to be read on them.

epoll_wait returns with data to be read on socket 8,10 and 11. Will the order of the file descriptors returned in the epoll array be 8, 10 and 11 or could they be jumbled?

like image 990
VSN Avatar asked Mar 19 '12 12:03

VSN


People also ask

What is an epoll file descriptor?

epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5. 44 of the Linux kernel. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them.

How does epoll Wait work?

The epoll_wait() system call waits for events on the epoll(7) instance referred to by the file descriptor epfd. The buffer pointed to by events is used to return information from the ready list about file descriptors in the interest list that have some events available. Up to maxevents are returned by epoll_wait().

What is a file descriptor in Linux?

A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.


1 Answers

The man page does not say anything specifically about the order, so it probably would not be a good idea to depend on the order when you call it. Even if they were returned in order in one implementation, they might not be in another. It would be best to assume that they could be returned in any order.

like image 182
Mark Wilkins Avatar answered Sep 23 '22 16:09

Mark Wilkins