Struct tipc::TipcConn [−][src]
Wrapper around a socket to provide convenience functions for binding, sending data, etc.
Implementations
impl TipcConn
[src]
pub fn socket_ref(&self) -> u32
[src]
pub fn node_ref(&self) -> u32
[src]
pub fn new(socktype: SockType) -> Result<Self, TipcError>
[src]
Create a new conn of a specific socket type.
pub fn set_sock_non_block(&mut self) -> Result<(), TipcError>
[src]
Set the socket to be non-blocking. This causes socket calls to return a
TipcError
with EAGAIN | EWOULDBLOCK error code set when it’s not possible
to send/recv on the socket.
pub fn connect(
&self,
service_type: u32,
service_instance: u32,
node: u32,
scope: TipcScope
) -> Result<(), TipcError>
[src]
&self,
service_type: u32,
service_instance: u32,
node: u32,
scope: TipcScope
) -> Result<(), TipcError>
Connect a stream socket.
pub fn listen(&self, backlog: i32) -> Result<(), TipcError>
[src]
Listen for incoming connections on a stream socket.
See Linux listen(2)
for definition of backlog
.
pub fn accept(&self) -> Result<Self, TipcError>
[src]
Accept a connection on a listening socket.
pub fn send(&self, data: &[u8]) -> Result<i32, TipcError>
[src]
Send data to the socket. Returns the number of bytes sent.
pub fn broadcast(&self, data: &[u8]) -> Result<i32, TipcError>
[src]
Broadcast data to every node in a group. Returns the number of bytes sent.
pub fn anycast(
&self,
data: &[u8],
service_type: u32,
service_instance: u32,
scope: TipcScope
) -> Result<i32, TipcError>
[src]
&self,
data: &[u8],
service_type: u32,
service_instance: u32,
scope: TipcScope
) -> Result<i32, TipcError>
Anycast data to a random node bound to service_type
and service_instance
. TIPC
protocol will round-robin available hosts. If this call is made in a group, TIPC will
also take into consideration the destination’s load, possible passing it by to
pick another node.
pub fn unicast(
&self,
data: &[u8],
socket_ref: u32,
node_ref: u32,
scope: TipcScope
) -> Result<i32, TipcError>
[src]
&self,
data: &[u8],
socket_ref: u32,
node_ref: u32,
scope: TipcScope
) -> Result<i32, TipcError>
Unicast data to a specific socket address. Returns the number of bytes sent.
pub fn multicast(
&self,
data: &[u8],
service_type: u32,
lower: u32,
upper: u32,
scope: TipcScope
) -> Result<i32, TipcError>
[src]
&self,
data: &[u8],
service_type: u32,
lower: u32,
upper: u32,
scope: TipcScope
) -> Result<i32, TipcError>
Multicast data to every node bound to service_type
. If not part of a group, the message
will be sent to any node bound in the range of lower
to upper
. If part of a group, the
message will be sent only to those nodes that are bound to lower
. Returns the number of
bytes sent.
pub fn join(
&mut self,
group_id: u32,
member_id: u32,
scope: TipcScope
) -> Result<(), TipcError>
[src]
&mut self,
group_id: u32,
member_id: u32,
scope: TipcScope
) -> Result<(), TipcError>
Join a group. If the group doesn’t exist, it is automatically created.
pub fn leave(&mut self) -> Result<(), TipcError>
[src]
Leave a group.
pub fn bind(
&self,
service_type: u32,
lower: u32,
upper: u32,
scope: TipcScope
) -> Result<(), TipcError>
[src]
&self,
service_type: u32,
lower: u32,
upper: u32,
scope: TipcScope
) -> Result<(), TipcError>
Bind to an address and range.
pub fn recv(&self, buf: &mut [u8; 66000]) -> Result<i32, TipcError>
[src]
Receive data from a socket, copying it to the passed in buffer. Returns the number of bytes received.
Example
let conn = TipcConn::new(SockType::SockRdm).unwrap(); conn.bind(88888, 0, 10, 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!("{}", std::str::from_utf8(&buf[0..msg_size as usize]).unwrap()) }
pub fn recvfrom(&self) -> Result<GroupMessage, TipcError>
[src]
Receive data or group membership messages from the socket.
Example
let mut conn = TipcConn::new(SockType::SockRdm).unwrap(); conn.join(88888, 10, TipcScope::Cluster).expect("Unable to join group"); loop { match conn.recvfrom() { Ok(msg) => match msg { GroupMessage::DataEvent(d) => { println!("group message: {}", std::str::from_utf8(&d).unwrap()) }, GroupMessage::MemberEvent(e) => { let event_type = if e.joined() { "joined" } else { "left" }; println!("member {} {}", e, event_type); }, } Err(e) => panic!("error receiving from socket: {}", e), } }
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for TipcConn
impl Send for TipcConn
impl Sync for TipcConn
impl Unpin for TipcConn
impl UnwindSafe for TipcConn
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,