2 releases
new 0.1.2 | Jan 6, 2025 |
---|---|
0.1.0 | Dec 22, 2024 |
#307 in Unix APIs
184 downloads per month
41KB
815 lines
Asyncfd
This crate wraps the complexities of sending and receiving file descriptors over Unix domain sockets while performing asynchronous reading and writing on the socket at the same time.
Usage
See the examples
directory.
Add Rust Crate Template as a dependency
# Cargo.toml
[dependencies]
asyncfd = "0.1.0"
Notable gotchas
There's no type information sent, so converting the RawFd
back to a typed file descriptor is
an inherently unsafe operation.
Message headers can become concatenated within the kernel. It is highly recommended to have a handshake between the two communicating processes to ensure that the file descriptors do not get mixed up. This crate does its best to maintain file descriptor send/receive ordering.
Similar crates
Both of these crates use dummy data to pass file descriptors, whereas this crate performs the file descriptor passing as a side channel to the standard read/write of the socket. With the wrapper provided in this crate, the socket can simply be used by Tokio in a normal way but the implementor can add and take file descriptors depending on the sent message.
This implementation supports Tokio, but does not take ownership of the RawFds and as such cannot
provide the AsyncRead
and AsyncWrite
traits meaning that much more boiler plate is required
by a use of this crate.
License
This project is licensed with the Apache v2.
Dependencies
~2–10MB
~94K SLoC