Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alshdavid/ipc-channel-adapter
https://github.com/alshdavid/ipc-channel-adapter
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alshdavid/ipc-channel-adapter
- Owner: alshdavid
- Created: 2024-05-11T04:36:12.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-13T10:28:07.000Z (about 1 month ago)
- Last Synced: 2024-11-24T19:19:13.013Z (about 1 month ago)
- Language: Rust
- Size: 71.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# IPC Channel Adapter
This utility wraps [ipc-channel](https://github.com/servo/ipc-channel) to handle the handshake and offers with standard channels.
This utility also offers a request/response wrapper for messages
It supports Tokio for non-blocking operation
## Usage
#### Parent Process
```rust
fn main() {
// Send requests to child
// Request to send to child is u32
// Response coming back from child u64
let child_sender = ChildSender::::new().unwrap();// Receive requests from child
// Request coming from child is u32
// Response to send back to child is u64
let (child_receiver, child_rx) = ChildReceiver::::new().unwrap();// Spawn child process and give it the names of the IPC channels
let child_process = spawn_child_process("your_child_process")
.env("IPC_RECEIVER_NAME", child_receiver.server_name)
.env("IPC_SENDER_NAME", child_sender.server_name)
.spawn();thread::spawn(move || {
while let Ok((v, reply)) = child_rx.recv() {
println!("[Host] Received: {}", v);
reply.send(v).unwrap()
}
});let response = child_sender.send_blocking(42);
println!("[Host] Response: {}", response);
}
```#### Child Process
```rust
fn main() {
// Get name of IPC servers
let host_receiver_server = env::var("IPC_RECEIVER_NAME").unwrap();
let host_sender_server = env::var("IPC_SENDER_NAME").unwrap();
// Send requests to host
// Request to send to host is u32
// Response coming back from host u64
let host_sender = HostSender::::new(&host_receiver_server).unwrap();// Receive requests from host
// Request coming from host is u32
// Response to send back to host is u64
let (_host_receiver, host_receiver_rx) = HostReceiver::::new(&host_sender_server).unwrap();thread::spawn(move || {
while let Ok((v, reply)) = host_receiver_rx.recv() {
println!("[Child] Received: {}", v);
reply.send(v).unwrap()
}
});let response = host_sender.send_blocking(43);
println!("[Child] Response: {}", response);
}
```