diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2023-07-15 20:36:39 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-07-16 02:48:01 +0200 |
commit | 7672f13007c7395afd4799bda1a260815ae7f0b6 (patch) | |
tree | 0c282638e4e0c0f929637a4e2fa1e6f0e0e25d28 | |
parent | 9695e5e2ea5a76bf34b7bc6c6465fa38cd559d35 (diff) |
pipe.7: document read()s with O_NONBLOCK
Which don't behave like you may expect them to;
unprimed, I expected the natural extension of either:
files (being a filesystem object), always returning 0 if no data, or
sockets (being an IPC mechanism), always EAGAINing if no data.
The pipe semantics make sense of course ‒ pipes can be modelled as
sockets if there aren't writers, but files if there are; indeed,
this makes sense as the writer continuously appending a sliding
"window" over a file ‒ but they're unique amongst the UNIX file types,
but arriving at that specific interaction table is non-obvious,
especially to a user.
Quoth Issue 8 Draft 3:
60746 When attempting to read from an empty pipe or FIFO:
60747 • If no process has the pipe open for writing, read( ) shall return 0 to indicate end-of-file.
60748 • If some process has the pipe open for writing and O_NONBLOCK is set, read( ) shall return
60749 −1 and set errno to [EAGAIN].
60750 • If some process has the pipe open for writing and O_NONBLOCK is clear, read( ) shall
60751 block the calling thread until some data is written or the pipe is closed by all processes that
60752 had the pipe open for writing.
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | man7/pipe.7 | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/man7/pipe.7 b/man7/pipe.7 index c3e06bdab..91554fa3c 100644 --- a/man7/pipe.7 +++ b/man7/pipe.7 @@ -56,12 +56,19 @@ If a process attempts to write to a full pipe (see below), then .BR write (2) blocks until sufficient data has been read from the pipe to allow the write to complete. +.PP Nonblocking I/O is possible by using the .BR fcntl (2) .B F_SETFL operation to enable the .B O_NONBLOCK -open file status flag. +open file status flag or by opening a +.BR fifo (7) +with +.BR O_NONBLOCK . +If any process has the pipe open for writing, reads fail with +.BR EAGAIN ; +otherwise\[em]with no potential writers\[em]reads succeed and return empty. .PP The communication channel provided by a pipe is a .IR "byte stream" : |