ipc-util

Provides simple cross-platform generic IPC message passing built on top of the interprocess crate.

Installation

Add this to your Cargo.toml:

toml [dependencies] ipc_util = "0.1"

Usage

Define your socket paths and a function that returns the correct path for the current platform:

```rust use ipcutil::*; use interprocess::localsocket::NameTypeSupport;

pub const MYSOCKETPATH: &str = "/tmp/my-socket.sock"; pub const MYSOCKETNAMESPACE: &str = "@my-socket.sock";

pub fn getipcname() -> &'static str { use NameTypeSupport::*; match NameTypeSupport::query() { OnlyPaths => MYSOCKETPATH, OnlyNamespaced | Both => MYSOCKETNAMESPACE, } } ```

Make sure the type that you want to send over the socket is properly de/serializable:

```rust

[derive(Serialize, Deserialize)]

pub enum Message { Text { text: String }, Ping, Pong, } ```

There are three functions that can be used to send messages to an IPC server as a client:

There are two functions that can be used to spawn an IPC server thread:

It's recommended to use start_ipc_server and its connection callback's Option<T> return type, where returning a Some variant will send that object as a response back to the client. This is intended to match up with the send_ipc_query function, which expects a response, while instances that return None to the callback will match up with send_ipc_message calls from clients.