Crate async_send_fd
source ·Expand description
async-send-fd is a library for sending and receiving Unix file descriptors over async UnixStream connections. You can either transfer
- RawFd;
- Tokio UnixStream if
tokio
feature enabled; - or Smol UnixStream if
smol
feature enabled;
§Examles
See test_raw_fd.rs, test_smol_stream.rs or test_tokio_stream.rs for examples.
§Creating a Tokio UnixStream from RawFd
If you make a Tokio UnixStream from a raw file descriptor made by an OS call (e.g. UnixStream::pair), you must make it set_nonblocking(true), otherwise receivers scheduler will block writing into the socket ⚠️
Smol UnixStream makes it automatically if created using UnixStream::from(Async::new(stream))
§Transfering socket pair ownership
Sending a descriptor doesn’t close the local copy, which leads to having the socket being opened by the sender until it shuts down. If you want socket pair receivers to detect peer shutdown, you have to close local sockets after sending them.
Use close Posix call for Tokio streams, or UnixStream::shutdown() for Smol.
§Features
tokio
- for Tokio supportsmol
- for Smol support
Traits§
- A trait to receive raw file descriptors
- A trait to send raw file descriptors