2 stable releases

1.0.1 Apr 8, 2024

#393 in Asynchronous

Download history 166/week @ 2024-04-05

166 downloads per month

MIT license

12KB
139 lines

async-send-fd

A library for sending and receiving Unix file descriptors over async UnixStream connections.

Crates.io MIT licensed Build Status

Overview

The crate is a library for sending and receiving Unix file descriptors over Tokio or Smol UnixStream connections. You can send RawFd or UnixStream using provided interfaces.

See test_smol_stream.rs or test_tokio_stream.rs for code examples.

Creating tokio::net::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 does 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 support
  • smol - for Smol support

Dependencies

~0–12MB
~115K SLoC