Struct SctpListener

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

SCTP listener which behaves like a TcpListener. A SCTP listener is used to wait for and accept one-to-one SCTP connections. An accepted connection is represented by SctpStream.

Implementations§

Source§

impl SctpListener

Source

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

Create a listener bound to a single address

Examples found in repository?
examples/listener.rs (line 5)
4fn main() {
5    match SctpListener::bind("0.0.0.0:3868") {
6        //	match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
7        Ok(serv) => {
8            println!("bound to {:?}", serv.local_addrs().unwrap());
9            //			serv.set_timeout(5).unwrap();
10            match serv.accept() {
11                Err(e) => println!("{:?}", e.kind()),
12                Ok((peer, _)) => {
13                    println!(
14                        "connection from {:?} on {:?}",
15                        peer.peer_addrs().unwrap(),
16                        peer.local_addrs().unwrap()
17                    );
18                    // Send message on stream 6
19                    peer.sendmsg("foobar\n".as_bytes(), 6).unwrap();
20                    let mut reply = [0u8; 1024];
21                    let (len, stream) = peer.recvmsg(&mut reply).unwrap();
22                    println!("Received {} bytes on stream {}", len, stream);
23                }
24            };
25        }
26        Err(e) => panic!("{:?}", e.kind()),
27    }
28}
Source

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

Create a listener bound to multiple addresses. Requires at least one address

Source

pub fn accept(&self) -> Result<(SctpStream, SocketAddr)>

Accept a new connection

Examples found in repository?
examples/listener.rs (line 10)
4fn main() {
5    match SctpListener::bind("0.0.0.0:3868") {
6        //	match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
7        Ok(serv) => {
8            println!("bound to {:?}", serv.local_addrs().unwrap());
9            //			serv.set_timeout(5).unwrap();
10            match serv.accept() {
11                Err(e) => println!("{:?}", e.kind()),
12                Ok((peer, _)) => {
13                    println!(
14                        "connection from {:?} on {:?}",
15                        peer.peer_addrs().unwrap(),
16                        peer.local_addrs().unwrap()
17                    );
18                    // Send message on stream 6
19                    peer.sendmsg("foobar\n".as_bytes(), 6).unwrap();
20                    let mut reply = [0u8; 1024];
21                    let (len, stream) = peer.recvmsg(&mut reply).unwrap();
22                    println!("Received {} bytes on stream {}", len, stream);
23                }
24            };
25        }
26        Err(e) => panic!("{:?}", e.kind()),
27    }
28}
Source

pub fn incoming(&self) -> Incoming<'_>

Iterate over new connections

Source

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

Get the listener local addresses

Examples found in repository?
examples/listener.rs (line 8)
4fn main() {
5    match SctpListener::bind("0.0.0.0:3868") {
6        //	match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
7        Ok(serv) => {
8            println!("bound to {:?}", serv.local_addrs().unwrap());
9            //			serv.set_timeout(5).unwrap();
10            match serv.accept() {
11                Err(e) => println!("{:?}", e.kind()),
12                Ok((peer, _)) => {
13                    println!(
14                        "connection from {:?} on {:?}",
15                        peer.peer_addrs().unwrap(),
16                        peer.local_addrs().unwrap()
17                    );
18                    // Send message on stream 6
19                    peer.sendmsg("foobar\n".as_bytes(), 6).unwrap();
20                    let mut reply = [0u8; 1024];
21                    let (len, stream) = peer.recvmsg(&mut reply).unwrap();
22                    println!("Received {} bytes on stream {}", len, stream);
23                }
24            };
25        }
26        Err(e) => panic!("{:?}", e.kind()),
27    }
28}
Source

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

Set timeout in seconds on accept

Source

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

Try to clone this listener

Trait Implementations§

Source§

impl AsRawFd for SctpListener

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl FromRawFd for SctpListener

Source§

unsafe fn from_raw_fd(fd: RawFd) -> SctpListener

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.