Skip to content

servo/ipc-channel

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

chore: use `panic!("{}", ...)` in prep. for Rust 2021 edition

This PR paves the way for migration to Rust 2021 (if the team is willing). Even if Rust 2021 is not interesting for `ipc-channel`'s roadmap, it's one less lint for `rustc` to report!
7f432aa

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
February 27, 2020 13:23
August 14, 2022 12:30
June 19, 2015 16:58
June 19, 2015 16:58

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.

About

A multiprocess drop-in replacement for Rust channels

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages