#ipc #channel #serde #linux #unix-sockets #transport #wire

ipc-channel

A multiprocess drop-in replacement for Rust channels

29 releases

0.16.0 Apr 11, 2022
0.15.0 Mar 12, 2021
0.14.1 Mar 26, 2020
0.13.0 Dec 20, 2019
0.1.0 Nov 30, 2015

#210 in Encoding

Download history 3807/week @ 2022-06-16 3901/week @ 2022-06-23 3614/week @ 2022-06-30 4384/week @ 2022-07-07 4462/week @ 2022-07-14 3685/week @ 2022-07-21 3347/week @ 2022-07-28 4377/week @ 2022-08-04 5629/week @ 2022-08-11 5029/week @ 2022-08-18 4781/week @ 2022-08-25 5252/week @ 2022-09-01 4831/week @ 2022-09-08 4301/week @ 2022-09-15 3536/week @ 2022-09-22 3236/week @ 2022-09-29

16,632 downloads per month
Used in 24 crates (17 directly)

MIT/Apache

715KB
17K SLoC

ipc-channel

πŸ“š Documentation πŸ“š

Overview

ipc-channel is an implementation of the Rust channel API (a form of communicating sequential processes, CSP) over the native OS abstractions. Under the hood, this API uses Mach ports on the Mac and file descriptor passing over Unix sockets on Linux. The serde library is used to serialize values for transport over the wire.

As much as possible, ipc-channel has been designed to be a drop-in replacement for Rust channels. The mapping from the Rust channel APIs to ipc-channel APIs is as follows:

  • channel() β†’ ipc::channel().unwrap()
  • Sender<T> β†’ ipc::IpcSender<T> (requires T: Serialize)
  • Receiver<T> β†’ ipc::IpcReceiver<T> (requires T: Deserialize)

Note that both IpcSender<T> and IpcReceiver<T> implement Serialize and Deserialize, so you can send IPC channels over IPC channels freely, just as you can with Rust channels.

The easiest way to make your types implement Serialize and Deserialize is to use the serde_macros crate from crates.io as a plugin and then annotate the types you want to send with #[derive(Deserialize, Serialize]). In many cases, that's all you need to doβ€”the compiler generates all the tedious boilerplate code needed to save and restore instances of your types.

In order to bootstrap an IPC connection across processes, you create an instance of the IpcOneShotServer type, register a global name, pass that name into the client process (perhaps with an environment variable or command line flag), and connect to the server in the client. See cross_process_embedded_senders() in test.rs for an example of how to do this using Unix fork() to spawn the process.

Major missing features

  • Servers only accept one client at a time. This is fine if you simply want to use this API to split your application up into a fixed number of mutually untrusting processes, but it's not suitable for implementing a system service. An API for multiple clients may be added later if demand exists for it.

Dependencies

~1.4–2.2MB
~40K SLoC