Struct SctpEndpoint

Source
pub struct SctpEndpoint(/* private fields */);
Expand description

One-to-many SCTP endpoint.

Implementations§

Source§

impl SctpEndpoint

Source

pub fn bind<A: ToSocketAddrs>(address: A) -> Result<SctpEndpoint>

Create a one-to-many SCTP endpoint bound to a single address

Examples found in repository?
examples/one_to_many.rs (line 6)
4fn main() {
5    // Create a new Sctp endpoint, and bind it to one or more socket addresses
6    let sock = match SctpEndpoint::bind("0.0.0.0:3868") {
7        //	let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
8        Ok(s) => s,
9        Err(e) => panic!("{:?}", e.kind()),
10    };
11    println!("Bound to {:?}", sock.local_addrs().unwrap());
12
13    let mut buf = [0u8; 1024];
14
15    // Read a message
16    match sock.recv_from(&mut buf) {
17        Ok((len, stream, addr)) => println!(
18            "Received {} bytes from {} on stream {} from {}",
19            len, addr, stream, addr
20        ),
21        Err(e) => println!("{:?}", e.kind()),
22    };
23
24    sock.send_to(&mut buf, "191.168.1.2:3868", 6).unwrap();
25}
Source

pub fn bindx<A: ToSocketAddrs>(addresses: &[A]) -> Result<SctpEndpoint>

Create a one-to-many SCTP endpoint bound to a multiple addresses. Requires at least one address

Source

pub fn recv_from(&self, msg: &mut [u8]) -> Result<(usize, u16, SocketAddr)>

Wait for data to be received. On success, returns a triplet containing the quantity of bytes received, the sctp stream id on which data were received, and the socket address used by the peer to send the data

Examples found in repository?
examples/one_to_many.rs (line 16)
4fn main() {
5    // Create a new Sctp endpoint, and bind it to one or more socket addresses
6    let sock = match SctpEndpoint::bind("0.0.0.0:3868") {
7        //	let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
8        Ok(s) => s,
9        Err(e) => panic!("{:?}", e.kind()),
10    };
11    println!("Bound to {:?}", sock.local_addrs().unwrap());
12
13    let mut buf = [0u8; 1024];
14
15    // Read a message
16    match sock.recv_from(&mut buf) {
17        Ok((len, stream, addr)) => println!(
18            "Received {} bytes from {} on stream {} from {}",
19            len, addr, stream, addr
20        ),
21        Err(e) => println!("{:?}", e.kind()),
22    };
23
24    sock.send_to(&mut buf, "191.168.1.2:3868", 6).unwrap();
25}
Source

pub fn send_to<A: ToSocketAddrs>( &self, msg: &mut [u8], address: A, stream: u16, ) -> Result<usize>

Send data in Sctp style, to the provided address on the stream stream. On success, returns the quantity on bytes sent

Examples found in repository?
examples/one_to_many.rs (line 24)
4fn main() {
5    // Create a new Sctp endpoint, and bind it to one or more socket addresses
6    let sock = match SctpEndpoint::bind("0.0.0.0:3868") {
7        //	let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
8        Ok(s) => s,
9        Err(e) => panic!("{:?}", e.kind()),
10    };
11    println!("Bound to {:?}", sock.local_addrs().unwrap());
12
13    let mut buf = [0u8; 1024];
14
15    // Read a message
16    match sock.recv_from(&mut buf) {
17        Ok((len, stream, addr)) => println!(
18            "Received {} bytes from {} on stream {} from {}",
19            len, addr, stream, addr
20        ),
21        Err(e) => println!("{:?}", e.kind()),
22    };
23
24    sock.send_to(&mut buf, "191.168.1.2:3868", 6).unwrap();
25}
Source

pub fn local_addrs(&self) -> Result<Vec<SocketAddr>>

Get local socket addresses to which this socket is bound

Examples found in repository?
examples/one_to_many.rs (line 11)
4fn main() {
5    // Create a new Sctp endpoint, and bind it to one or more socket addresses
6    let sock = match SctpEndpoint::bind("0.0.0.0:3868") {
7        //	let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
8        Ok(s) => s,
9        Err(e) => panic!("{:?}", e.kind()),
10    };
11    println!("Bound to {:?}", sock.local_addrs().unwrap());
12
13    let mut buf = [0u8; 1024];
14
15    // Read a message
16    match sock.recv_from(&mut buf) {
17        Ok((len, stream, addr)) => println!(
18            "Received {} bytes from {} on stream {} from {}",
19            len, addr, stream, addr
20        ),
21        Err(e) => println!("{:?}", e.kind()),
22    };
23
24    sock.send_to(&mut buf, "191.168.1.2:3868", 6).unwrap();
25}
Source

pub fn shutdown(&self, how: Shutdown) -> Result<()>

Shuts down the read, write, or both halves of this connection

Source

pub fn set_nodelay(&self, nodelay: bool) -> Result<()>

Set or unset SCTP_NODELAY option

Source

pub fn has_nodelay(&self) -> Result<bool>

Verify if SCTP_NODELAY option is activated for this socket

Source

pub fn set_buffer_size(&self, dir: SoDirection, size: usize) -> Result<()>

Set the socket buffer size for the direction specified by dir. Linux systems will double the provided size

Source

pub fn get_buffer_size(&self, dir: SoDirection) -> Result<usize>

Get the socket buffer size for the direction specified by dir

Source

pub fn set_timeout(&self, dir: SoDirection, timeout: i32) -> Result<()>

Set timeout in seconds for operation dir (either receive or send)

Source

pub fn try_clone(&self) -> Result<SctpEndpoint>

Try to clone this socket

Trait Implementations§

Source§

impl AsRawFd for SctpEndpoint

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl FromRawFd for SctpEndpoint

Source§

unsafe fn from_raw_fd(fd: RawFd) -> SctpEndpoint

Constructs a new instance of Self from the given raw file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.