UdpSocket

Struct UdpSocket 

Source
pub struct UdpSocket { /* private fields */ }
Expand description

An UDP socket bound to an address.

The recv_from, send_to, recv, and send can be interrupted using the Canceller object created with the socket.

Otherwise similar to std::net::UdpSocket.

Implementations§

Source§

impl UdpSocket

Source

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.

Source

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.

Source

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.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Gets the socket address that this object was created from.

Source

pub fn try_clone(&self) -> Result<(Self, Canceller)>

Creates a new independently owned handle to the underlying socket.

Source

pub fn set_read_timeout(&self, duration: Option<Duration>) -> Result<()>

Sets the read timeout to the timeout specified.

Source

pub fn set_write_timeout(&self, duration: Option<Duration>) -> Result<()>

Sets the write timeout to the timeout specified.

Source

pub fn read_timeout(&self) -> Result<Option<Duration>>

Returns the read timeout of this socket.

Source

pub fn write_timeout(&self) -> Result<Option<Duration>>

Returns the write timeout of this socket.

Source

pub fn set_broadcast(&self, broadcast: bool) -> Result<()>

Sets the value of the SO_BROADCAST option for this socket.

Source

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

Gets the value of the SO_BROADCAST option for this socket.

Source

pub fn set_multicast_loop_v4(&self, multicast_loop: bool) -> Result<()>

Sets the value of the IP_MULTICAST_LOOP option for this socket.

Source

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

Gets the value of the IP_MULTICAST_LOOP option for this socket.

Source

pub fn set_multicast_ttl_v4(&self, multicast_ttl: u32) -> Result<()>

Sets the value of the IP_MULTICAST_TTL option for this socket.

Source

pub fn multicast_ttl_v4(&self) -> Result<u32>

Gets the value of the IP_MULTICAST_TTL option for this socket.

Source

pub fn set_multicast_loop_v6(&self, multicast_loop: bool) -> Result<()>

Sets the value of the IPV6_MULTICAST_LOOP option for this socket.

Source

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

Gets the value of the IPV6_MULTICAST_LOOP option for this socket.

Source

pub fn set_ttl(&self, ttl: u32) -> Result<()>

Sets the value for the IP_TTL option on this socket.

Source

pub fn ttl(&self) -> Result<u32>

Gets the value for the IP_TTL option for this socket.

Source

pub fn join_multicast_v4( &self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr, ) -> Result<()>

Executes an operation of the IP_ADD_MEMBERSHIP type.

Source

pub fn join_multicast_v6( &self, multiaddr: &Ipv6Addr, interface: u32, ) -> Result<()>

Executes an operation of the IPV6_ADD_MEMBERSHIP type.

Source

pub fn leave_multicast_v4( &self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr, ) -> Result<()>

Executes an operation of the IP_DROP_MEMBERSHIP type.

Source

pub fn leave_multicast_v6( &self, multiaddr: &Ipv6Addr, interface: u32, ) -> Result<()>

Executes an operation of the IPV6_DROP_MEMBERSHIP type.

Source

pub fn take_error(&self) -> Result<Option<Error>>

Gets the value of the SO_ERROR option for this socket.

Source

pub fn set_only_v6(&self, only_v6: bool) -> Result<()>

Sets the value for the IPV6_V6ONLY option on this socket.

Source

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

Gets the value for the IPV6_V6ONLY option for this socket.

Source

pub fn connect<A: ToSocketAddrs>(&self, address: A) -> Result<()>

Connects this socket to a remote address.

Source

pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>

Moves this socket into or out of non blocking mode.

Source

pub fn recv(&self, buf: &mut [u8]) -> Result<usize>

Receives a single datagram from the connected remote address.

This method can be cancelled by the associated Canceller object.

Source

pub fn send(&self, buf: &[u8]) -> Result<usize>

Sends a single datagram to the connected remote address.

This method can be cancelled by the associated Canceller object.

Trait Implementations§

Source§

impl Debug for UdpSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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.