Trait udp_sas_async::UdpSas

source ·
pub trait UdpSas: Sized {
    // Required methods
    fn bind_sas<A: ToSocketAddrs>(addr: A) -> Result<Self>;
    fn send_sas(
        &self,
        buf: &[u8],
        target: &SocketAddr,
        local: &IpAddr
    ) -> Result<usize>;
    fn recv_sas(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr, IpAddr)>;
}
Expand description

An extension trait to support source address selection in std::net::UdpSocket

See module level documentation for more details.

Required Methods§

source

fn bind_sas<A: ToSocketAddrs>(addr: A) -> Result<Self>

Creates a UDP socket from the given address.

The address type can be any implementor of ToSocketAddrs trait. See its documentation for concrete examples.

The new socket is configured with the IP_PKTINFO or IPV6_RECVPKTINFO option enabled.

Examples
use std::net::UdpSocket;
use udp_sas_async::UdpSas;

let socket = UdpSocket::bind_sas("127.0.0.1:34254").expect("couldn't bind to address");
source

fn send_sas( &self, buf: &[u8], target: &SocketAddr, local: &IpAddr ) -> Result<usize>

Sends a datagram to the given target address and use the local address as its source.

On success, returns the number of bytes written.

source

fn recv_sas(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr, IpAddr)>

Receive a datagram

On success, returns a tuple (nb, source, local) containing the number of bytes read, the source socket address (peer address), and the destination ip address (local address).

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl UdpSas for UdpSocket

source§

fn bind_sas<A: ToSocketAddrs>(addr: A) -> Result<UdpSocket>

source§

fn send_sas( &self, buf: &[u8], target: &SocketAddr, local: &IpAddr ) -> Result<usize>

source§

fn recv_sas(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr, IpAddr)>

Implementors§