pub struct UdpSocket { /* private fields */ }Expand description
Implementations§
Source§impl UdpSocket
impl UdpSocket
Sourcepub fn bind<A: ToSocketAddrs>(address: A) -> Result<(Self, Canceller)>
pub fn bind<A: ToSocketAddrs>(address: A) -> Result<(Self, Canceller)>
Creates an UDP socket from the given address, together with an object that can be used to cancel send/recv operations.
Sourcepub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
Receives a single datagram message from the socket.
This method can be cancelled by the associated Canceller object.
Sourcepub fn send_to(&self, buf: &[u8], addr: &SocketAddr) -> Result<usize>
pub fn send_to(&self, buf: &[u8], addr: &SocketAddr) -> Result<usize>
Sends a single datagram message to the given address.
This method can be cancelled by the associated Canceller object.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Gets the socket address that this object was created from.
Sourcepub fn try_clone(&self) -> Result<(Self, Canceller)>
pub fn try_clone(&self) -> Result<(Self, Canceller)>
Creates a new independently owned handle to the underlying socket.
Sourcepub fn set_read_timeout(&self, duration: Option<Duration>) -> Result<()>
pub fn set_read_timeout(&self, duration: Option<Duration>) -> Result<()>
Sets the read timeout to the timeout specified.
Sourcepub fn set_write_timeout(&self, duration: Option<Duration>) -> Result<()>
pub fn set_write_timeout(&self, duration: Option<Duration>) -> Result<()>
Sets the write timeout to the timeout specified.
Sourcepub fn read_timeout(&self) -> Result<Option<Duration>>
pub fn read_timeout(&self) -> Result<Option<Duration>>
Returns the read timeout of this socket.
Sourcepub fn write_timeout(&self) -> Result<Option<Duration>>
pub fn write_timeout(&self) -> Result<Option<Duration>>
Returns the write timeout of this socket.
Sourcepub fn set_broadcast(&self, broadcast: bool) -> Result<()>
pub fn set_broadcast(&self, broadcast: bool) -> Result<()>
Sets the value of the SO_BROADCAST option for this socket.
Sourcepub fn broadcast(&self) -> Result<bool>
pub fn broadcast(&self) -> Result<bool>
Gets the value of the SO_BROADCAST option for this socket.
Sourcepub fn set_multicast_loop_v4(&self, multicast_loop: bool) -> Result<()>
pub fn set_multicast_loop_v4(&self, multicast_loop: bool) -> Result<()>
Sets the value of the IP_MULTICAST_LOOP option for this socket.
Sourcepub fn multicast_loop_v4(&self) -> Result<bool>
pub fn multicast_loop_v4(&self) -> Result<bool>
Gets the value of the IP_MULTICAST_LOOP option for this socket.
Sourcepub fn set_multicast_ttl_v4(&self, multicast_ttl: u32) -> Result<()>
pub fn set_multicast_ttl_v4(&self, multicast_ttl: u32) -> Result<()>
Sets the value of the IP_MULTICAST_TTL option for this socket.
Sourcepub fn multicast_ttl_v4(&self) -> Result<u32>
pub fn multicast_ttl_v4(&self) -> Result<u32>
Gets the value of the IP_MULTICAST_TTL option for this socket.
Sourcepub fn set_multicast_loop_v6(&self, multicast_loop: bool) -> Result<()>
pub fn set_multicast_loop_v6(&self, multicast_loop: bool) -> Result<()>
Sets the value of the IPV6_MULTICAST_LOOP option for this socket.
Sourcepub fn multicast_loop_v6(&self) -> Result<bool>
pub fn multicast_loop_v6(&self) -> Result<bool>
Gets the value of the IPV6_MULTICAST_LOOP option for this socket.
Sourcepub fn set_ttl(&self, ttl: u32) -> Result<()>
pub fn set_ttl(&self, ttl: u32) -> Result<()>
Sets the value for the IP_TTL option on this socket.
Sourcepub fn join_multicast_v4(
&self,
multiaddr: &Ipv4Addr,
interface: &Ipv4Addr,
) -> Result<()>
pub fn join_multicast_v4( &self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr, ) -> Result<()>
Executes an operation of the IP_ADD_MEMBERSHIP type.
Sourcepub fn join_multicast_v6(
&self,
multiaddr: &Ipv6Addr,
interface: u32,
) -> Result<()>
pub fn join_multicast_v6( &self, multiaddr: &Ipv6Addr, interface: u32, ) -> Result<()>
Executes an operation of the IPV6_ADD_MEMBERSHIP type.
Sourcepub fn leave_multicast_v4(
&self,
multiaddr: &Ipv4Addr,
interface: &Ipv4Addr,
) -> Result<()>
pub fn leave_multicast_v4( &self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr, ) -> Result<()>
Executes an operation of the IP_DROP_MEMBERSHIP type.
Sourcepub fn leave_multicast_v6(
&self,
multiaddr: &Ipv6Addr,
interface: u32,
) -> Result<()>
pub fn leave_multicast_v6( &self, multiaddr: &Ipv6Addr, interface: u32, ) -> Result<()>
Executes an operation of the IPV6_DROP_MEMBERSHIP type.
Sourcepub fn take_error(&self) -> Result<Option<Error>>
pub fn take_error(&self) -> Result<Option<Error>>
Gets the value of the SO_ERROR option for this socket.
Sourcepub fn set_only_v6(&self, only_v6: bool) -> Result<()>
pub fn set_only_v6(&self, only_v6: bool) -> Result<()>
Sets the value for the IPV6_V6ONLY option on this socket.
Sourcepub fn only_v6(&self) -> Result<bool>
pub fn only_v6(&self) -> Result<bool>
Gets the value for the IPV6_V6ONLY option for this socket.
Sourcepub fn connect<A: ToSocketAddrs>(&self, address: A) -> Result<()>
pub fn connect<A: ToSocketAddrs>(&self, address: A) -> Result<()>
Connects this socket to a remote address.
Sourcepub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
Moves this socket into or out of non blocking mode.