pub fn write_without_waiting(fd: i32, bytes: &[u8])Expand description
Put bytes on fd once, without waiting for the other end and without
letting the attempt raise a signal. A diagnostic that cannot be delivered
that way is omitted: the exit status still says why the run ended.
THE DESCRIPTOR ITSELF IS NEVER MADE NON-BLOCKING. An inherited descriptor’s
open file description is shared with the parent, the guest or a terminal,
and fcntl(O_NONBLOCK) on it would leak into all of them. Each kind of file
instead gets a primitive that is non-blocking on its own:
- a regular file:
pwritev2(RWF_NOWAIT)at offset -1, so the file position andO_APPENDare honoured.EAGAINorEOPNOTSUPPomit the line. BufferedRWF_NOWAITwrites fail withEAGAINon btrfs and withEOPNOTSUPPon tmpfs, so a log file there does not get the line. - a socket:
send(MSG_DONTWAIT | MSG_NOSIGNAL). - a pipe, FIFO or terminal: a NEW open file description for the same
object, opened through
/proc/self/fd/<fd>withO_NONBLOCK, and one write of at mostPIPE_BUFbytes, which a pipe either takes whole or refuses withEAGAIN. Opening a pipe that has no reader fails withENXIOrather than raisingSIGPIPE. - anything else, including a descriptor whose type cannot be learned: omitted.
The file type comes from file_type in this module.
No signal escapes; see suppressing_diagnostic_signals.
What this cannot avoid are short kernel locks that sleep uninterruptibly, which no handled signal or timer could break either: the file-position lock of an open file description another process is writing through at that moment, a terminal’s termios and output locks, a socket’s lock. None of them waits for a reader to drain anything.