DataPath

com-xaymar-datapath

DataPath is an IPC library for fast and predictable messaging between processes on the same machine made in C++11 (or newer). Designed from the ground up to care about the worst case it is able to outperform or match existing solutions such as boost interprocess, libuv, Mojo and others. It allows for packets from a few bytes all the way to many megabytes between one server and any number of clients. The exact implementation varies by platform and makes use of the best measured available systems.

These are the official bindings for DataPath

Features

Rust specific Features

Rust specific Differences

Usage

cargo add com-xaymar-datapath --rename datapath
use datapath::Socket;
use std::sync::{Arc, Mutex};

// Server: echo every message.
let server = datapath::host("my-service")?;
let clients = Arc::new(Mutex::new(Vec::<Socket>::new()));
let keep = clients.clone();
server.on_accept(move |client: Socket| {
    client.on_message(|sock, data| { let _ = sock.send(data); }).ok();
    client.on_close(|_, reason| println!("client left: {reason}")).ok();
    keep.lock().unwrap().push(client);                 // keep it, or the connection closes
})?;

// Client.
let sock = datapath::connect("my-service")?;
sock.on_message(|_, data| println!("{}", String::from_utf8_lossy(data)))?;  // "hello"
sock.send(b"hello")?;
sock.send_vectored(&[b"he".as_slice(), b"llo"])?;      // one message from several parts, without joining them first
sock.close()?;
server.close()?;

See examples/echo.rs for a complete program.

API

License

BSD 3-Clause License, see LICENSE.

View this page on GitHub