pub fn register_raw(signal: c_int, pipe: RawFd) -> Result<SigId, Error>
Available on non-Windows only.
Expand description

Registers a write to a self-pipe whenever there’s the signal.

In this case, the pipe is taken as the RawFd. It’ll be closed on deregistration. Effectively, the function takes ownership of the file descriptor. This includes feeling free to set arbitrary flags on it, including file status flags (that are shared across file descriptors created by dup).

Note that passing the wrong file descriptor won’t cause UB, but can still lead to severe bugs ‒ like data corruptions in files. Prefer using register if possible.

Also, it is perfectly legal for multiple writes to be collated together (if not consumed) and to generate spurious wakeups (but will not generate spurious bytes in the pipe).

Internal details

Internally, it currently does following. Note that this is not part of the stability guarantees and may change if necessary.

  • If the file descriptor can be used with send, it’ll be used together with MSG_DONTWAIT. This is tested by sending 0 bytes of data (depending on the socket type, this might wake the read end with an empty message).
  • If it is not possible, the O_NONBLOCK will be set on the file descriptor and write will be used instead.