pub struct SctpEndpoint(/* private fields */);
Expand description
One-to-many SCTP endpoint.
Implementations§
Source§impl SctpEndpoint
impl SctpEndpoint
Sourcepub fn bind<A: ToSocketAddrs>(address: A) -> Result<SctpEndpoint>
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?
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}
Sourcepub fn bindx<A: ToSocketAddrs>(addresses: &[A]) -> Result<SctpEndpoint>
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
Sourcepub fn recv_from(&self, msg: &mut [u8]) -> Result<(usize, u16, SocketAddr)>
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?
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}
Sourcepub fn send_to<A: ToSocketAddrs>(
&self,
msg: &mut [u8],
address: A,
stream: u16,
) -> Result<usize>
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?
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}
Sourcepub fn local_addrs(&self) -> Result<Vec<SocketAddr>>
pub fn local_addrs(&self) -> Result<Vec<SocketAddr>>
Get local socket addresses to which this socket is bound
Examples found in repository?
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}
Sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
Shuts down the read, write, or both halves of this connection
Sourcepub fn set_nodelay(&self, nodelay: bool) -> Result<()>
pub fn set_nodelay(&self, nodelay: bool) -> Result<()>
Set or unset SCTP_NODELAY option
Sourcepub fn has_nodelay(&self) -> Result<bool>
pub fn has_nodelay(&self) -> Result<bool>
Verify if SCTP_NODELAY option is activated for this socket
Sourcepub fn set_buffer_size(&self, dir: SoDirection, size: usize) -> Result<()>
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
Sourcepub fn get_buffer_size(&self, dir: SoDirection) -> Result<usize>
pub fn get_buffer_size(&self, dir: SoDirection) -> Result<usize>
Get the socket buffer size for the direction specified by dir
Sourcepub fn set_timeout(&self, dir: SoDirection, timeout: i32) -> Result<()>
pub fn set_timeout(&self, dir: SoDirection, timeout: i32) -> Result<()>
Set timeout
in seconds for operation dir
(either receive or send)
Sourcepub fn try_clone(&self) -> Result<SctpEndpoint>
pub fn try_clone(&self) -> Result<SctpEndpoint>
Try to clone this socket
Trait Implementations§
Source§impl AsRawFd for SctpEndpoint
impl AsRawFd for SctpEndpoint
Source§impl FromRawFd for SctpEndpoint
impl FromRawFd for SctpEndpoint
Source§unsafe fn from_raw_fd(fd: RawFd) -> SctpEndpoint
unsafe fn from_raw_fd(fd: RawFd) -> SctpEndpoint
Self
from the given raw file
descriptor. Read more