diff options
| author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2023-06-24 14:13:29 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2023-07-08 18:32:59 +0200 |
| commit | f9f86b3d5f11ff9e3035e6f27cc57a333809e05e (patch) | |
| tree | 3410066efb31fba007a7dcb3392ccfae88a3ef65 | |
| parent | afb2a42b4e393b08129d52fc200e36010305da3d (diff) | |
| download | man-pages-f9f86b3d5f11ff9e3035e6f27cc57a333809e05e.tar.gz | |
poll.2: explicitly say what happens for regular files &c.
Naively, one may consider being "ready" to mean, for example,
lseek(0, 0, SEEK_END); poll({.fd = 0, .events = POLLIN}, 0);
to be able to say whether new data has appeared at the end of the file.
This is not the case, and poll() is only meaningful as
"will a read or a write sleep": regular files and block devices are
always ready to return an empty read in this case, for example,
and you need to use inotify to achieve this.
Under Linux this is governed by DEFAULT_POLLMASK
(EPOLLIN | EPOLLOUT | EPOLLRDNORM | EPOLLWRNORM)
being returned if no explicit poll operation is defined for the file.
As contrast, unpollables like the above are refused by epoll_ctl(ADD).
I explicitly hit the two keywords I searched for (regular, block)
before just writing a test program to confirm that poll() behaved as
expected and is not a good fit for my use-case.
This behaviour is guaranteed by POSIX (Issue 8 Draft 3):
51381 The poll( ) and ppoll( ) functions shall support regular files, terminal and pseudo-terminal
51382 devices, FIFOs, pipes, and sockets. The behavior of poll( ) and ppoll( ) on elements of fds that refer
51383 to other types of file is unspecified.
51384 Regular files shall always poll TRUE for reading and writing.
51385 A file descriptor for a socket that is listening for connections shall indicate that it is ready for
51386 reading, once connections are available. A file descriptor for a socket that is connecting
51387 asynchronously shall indicate that it is ready for writing, once a connection has been established.
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
| -rw-r--r-- | man2/poll.2 | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/man2/poll.2 b/man2/poll.2 index 0b834306ac..d56cde8875 100644 --- a/man2/poll.2 +++ b/man2/poll.2 @@ -123,6 +123,14 @@ the call is interrupted by a signal handler; or .IP \[bu] the timeout expires. .PP +Being "ready" means that the requested operation will not block; thus, +.BR poll ()ing +regular files, +block devices, +and other files with no reasonable polling semantic +.I always +returns instantly as ready to read and write. +.PP Note that the .I timeout interval will be rounded up to the system clock granularity, |
