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

2

6

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?

Bookerbookie answered 19/3, 2012 at 12:39 Comment(1)
I need it for implementation... If it's in the same order, then I'd just readily use the index for the one I want and check if it's set.Bookerbookie
Z
3

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.

Zerla answered 19/3, 2012 at 12:54 Comment(4)
I looked here: " lxr.free-electrons.com/source/fs/eventpoll.c " for clues. I couldn't figure out much here :(Bookerbookie
@VSN: I also looked for the source but could not find any for that specific function. But even finding an implementation would not be conclusive since another implementation could differ. I would, however, certainly be interesting.Zerla
Thanks for all the trouble :DBookerbookie
It does make sense to ask oneself about the order, for performance purposes.Genteel
R
0

Just think about it logically. Presumably they're not all marked as readable as a single atomic operation, and epoll_wait might then just as well just return 1 fd available each time it's called. It makes no sense to depend on the order of it's output.

Reins answered 19/3, 2012 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.