Files
firestuff/2016-03-02-more_poll_epoll_fun.html
2019-04-15 01:15:07 +00:00

21 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--# set var="title" value="More poll()/epoll fun" -->
<!--# set var="date" value="March 2, 2016" -->
<!--# include file="include/top.html" -->
<p>I generally assume that select(), poll(), and epoll are interfaces to the same thing. Sure, they have different input flags (notably, epoll suppports edge-triggered), but I expect that each is a superset of the previous, with a better interface for large numbers of fds.</p>
<p>Of course, though, there are quirks. poll() and epoll behave very differently if youve got some fds to regular files in the mix. I spent awhile chasing this, because people all over the web claim that poll() doesnt work on regular files. It actually does; <a href="https://bugzilla.kernel.org/show_bug.cgi?id=15272">this bug</a> has a decent description.</p>
<blockquote>
<p>If you look at fs/select.c, line 723 to 731, you notice that in case f_op->poll is not provided by the device, DEFAULT_POLLMASK is used as returned mask, where DEFAULT_POLLMASK is defined as (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM).</p>
<p>Later on, this DEFAULT_POLLMASK is masked with your mask, which returns POLLIN, even though no test have been really performed with the device, since a file device does not provide an f_op->poll() function.</p>
<p>Epoll will fail you explicitly, while poll/select will not. but nothing meaningful is returned from poll/select on file system files.</p>
</blockquote>
<p>Unfortunately, the poll() behavior is probably what you want (a regular file is always readable, because theres either more data or youre at EOF). If you want to get the same behavior in an epoll loop, youve got to keep a separate list of regular fds that failed epoll_ctl(EPOLL_CTL_ADD) with EPERM, and treat them as always readable/writable within your code. Linux should really add an EPOLL_SHUT_UP_I_KNOW_ITS_JUST_A_FILE that emulates the poll() behavior and saves implementors the complexity.</p>
<!--# include file="include/bottom.html" -->