Communication between processes using shared memory.
A typical use case could be audio/video streaming.
Don't need maximum performance and minimal latency? Try D-Bus.
Transferring small amounts of data? Then a unix socket is easier to set up and has similar performance.
As for Linux, this crate uses memfd sealing to ensure safety between untrusted processes, and ringbuffer signaling is done using eventfd for best performance. These two features are Linux only.
You probably want to start in the sharedring
module, which sets up a lock-free ringbuffer
between untrusted processes. Another useful function is mem::oneshot
for a scenario where
you write data once and make it available for reading afterwards. The mem
and ringbuf
modules contain building blocks that might be useful in other use cases.
The downside of using memfd based shared memory is that you need to set it up by transferring file descriptors, using some other way of communication. Using D-Bus would be the standard way of doing that - it's also possible using unix sockets.
There is also a client/server example in the examples
directory that can help you get started.
Enjoy!
The code is Apache 2.0 / MIT dual licensed. Any code submitted in Pull Requests, discussions or issues is assumed to have this license, unless explicitly stated otherwise.