Viaduct is a library for establishing a duplex communication channel between a parent and child process, using unnamed pipes.
Example
Shared library
Parent process
let child = new;
let = parent.unwrap;
spawn;
tx.rpc.unwrap;
tx.rpc.unwrap;
tx.rpc.unwrap;
let response = tx.request.unwrap;
assert_eq!;
Child process
let = child.unwrap;
spawn;
tx.rpc.unwrap;
tx.rpc.unwrap;
tx.rpc.unwrap;
let response = tx.request.unwrap;
assert_eq!;
Use Cases
Viaduct was designed for separating user interface from application logic in a cross-platform manner.
For example, an application may want to run a GUI in a separate process from the application logic, for modularity or performance reasons.
Viaduct allows for applications like this to communicate between these processes in a natural way, without having to manually implement IPC machinery & synchronization.
Usage
Serialization
Viaduct currently supports serialization and deserialization of data using bincode or speedy at your choice, using the respective Cargo feature flags.
You can also manually implement the [Pipeable] trait.
Initializing a viaduct
A viaduct is initialized by calling [ViaductBuilder::parent] as the parent process, which will spawn your child process.
Your child process should then call [ViaductBuilder::child], [ViaductBuilder::child_with_args_os], [ViaductBuilder::child_with_args] (see CAVEAT below) to bridge the connection between the parent and child.
Then, you are ready to start...
Passing data
Viaduct has two modes of operation: RPCs and Requests/Responses.
RPCs are one-way messages, and are useful for sending notifications to the other process.
Requests/Responses are two-way messages, and are useful for sending requests to the other process and receiving data as a response.
Requests will block any other thread trying to send requests and RPCs through the viaduct, until a response is received.
CAVEAT: Don't use [std::env::args_os] or [std::env::args] in your child process!
The child process should not use args_os or args to get its arguments, as these will contain data Viaduct needs to pass to the child process.
Instead, use the argument iterator provided by [ViaductBuilder::child_with_args_os] or [ViaductBuilder::child_with_args] for args_os and args respectively.
License
Viaduct is licensed under the MIT license or the Apache License v2.0, at your choice.