Re: epoll_wait conflicts with man page

Jamie Lokier (lk@tantalophile.demon.co.uk)
Sun, 24 Nov 2002 20:46:33 +0000


Felix von Leitner wrote:
> Also, I would move the
> "int fd" out of the union because it is universally useful to know the
> file descriptor without having to save it in the opaque data.

Hi Felix,

It is not possible for epoll itself to keep track of the fd number,
because some more advanced applications can change or duplicate fd
numbers (using dup(), dup2() or fcntl(F_DUPFD)), and in some cases its
possible for an event to arrive on an object which doesn't even _any_
valid fd value in the current process (e.g. while it's being passed
from one process to another through a unix domain socket, or with
certain uses of clone()).

While this might seem peculiar, it is the sort of thing that some
kinds of scalable server software do, for good reasons.

The only thing epoll could report would be the initially registered
"fd" value, which is meaningful for some applications but not
universally correct. As it would not always be correct, it is best
for the application itself to keep track of fd numbers. In practice,
all applications either use the `fd' field in the union (and no other
user-data), or a pointer in the union to a structure of flags and
other per-fd data, and that structure always includes a correct `fd'
value anyway for other reasons.

So, the API is perfect as it is :)

-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/