[−][src]Crate tipc
Linux Transparent Inter Process Communication (TIPC) bindings for Rust
This library provides bindings for some of the more common TIPC operations.
Prerequisites
- Linux OS (version >= 4.14 for communication groups)
- Clang compiler
- TIPC kernel module enabled (
sudo modprobe tipc
)
Open a socket, bind to an address and listen for messages
ⓘThis example is not tested
use tipc::{TipcConn, SockType, TipcScope}; let conn = TipcConn::new(SockType::SockRdm).unwrap(); conn.bind(12345, 0, 0, TipcScope::Cluster).expect("Unable to bind to address"); let mut buf: [u8; tipc::MAX_MSG_SIZE] = [0; tipc::MAX_MSG_SIZE]; loop { let msg_size = conn.recv(&mut buf).unwrap(); println!("received: {}", std::str::from_utf8(&buf[0..msg_size as usize]).unwrap()) }
Join a group and listen for group membership events or messages
Note: Joining a group automatically binds to an address and creates the group if it doesn't already exist.
ⓘThis example is not tested
use tipc::{TipcConn, SockType, TipcScope, GroupMessage}; let mut conn = TipcConn::new(SockType::SockRdm).unwrap(); conn.join(12345, 1, TipcScope::Cluster).expect("Unable to join group"); // Listen for messages loop { match conn.recvfrom().unwrap() { GroupMessage::MemberEvent(e) => { let action = if e.joined() { "joined" } else { "left" }; println!("group member {}:{} {}", e.socket_ref(), e.node_ref(), action); }, GroupMessage::DataEvent(d) => { println!("received message: {}", std::str::from_utf8(&d).unwrap()); } } }
Structs
Membership | Information about a node that joined/left a group. |
TipcConn | Wrapper around a socket to provide convenience functions for binding, sending data, etc. |
TipcError | Error information about the attempted TIPC operation |
Enums
GroupMessage | Represents the message type received when in a group. |
SockType | TIPC socket type to be used. |
TipcScope | The scope to use when binding to an address. |
Constants
MAX_MSG_SIZE |
Functions
attach_to_interface | Attach TIPC to an interface to allow communication with other nodes on the network. |
set_host_addr | Set the host addr, can be omitted starting from Linux 4.17. |