Struct UdpSocket

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

Wrapper around a tokio UDP socket.

Implementations§

Source§

impl UdpSocket

Source

pub fn bind_v4(port: u16) -> Result<Self>

Bind only Ipv4 on any interface.

Source

pub fn bind_v6(port: u16) -> Result<Self>

Bind only Ipv6 on any interface.

Source

pub fn bind_local_v4(port: u16) -> Result<Self>

Bind only Ipv4 on localhost.

Source

pub fn bind_local_v6(port: u16) -> Result<Self>

Bind only Ipv6 on localhost.

Source

pub fn bind_local(network: IpFamily, port: u16) -> Result<Self>

Bind to the given port only on localhost.

Source

pub fn bind(network: IpFamily, port: u16) -> Result<Self>

Bind to the given port and listen on all interfaces.

Source

pub fn bind_full(addr: impl Into<SocketAddr>) -> Result<Self>

Bind to any provided SocketAddr.

Source

pub fn is_broken(&self) -> bool

Is the socket broken and needs a rebind?

Source

pub fn rebind(&self) -> Result<()>

Rebind the underlying socket.

Source

pub fn recv<'a, 'b>(&'b self, buffer: &'a mut [u8]) -> RecvFut<'a, 'b>

Receives a single datagram message on the socket from the remote address to which it is connected. On success, returns the number of bytes read.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

The connect method will connect this socket to a remote address. This method will fail if the socket is not connected.

Source

pub fn recv_from<'a, 'b>(&'b self, buffer: &'a mut [u8]) -> RecvFromFut<'a, 'b>

Receives a single datagram message on the socket. On success, returns the number of bytes read and the origin.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

Source

pub fn send<'a, 'b>(&'b self, buffer: &'a [u8]) -> SendFut<'a, 'b>

Sends data on the socket to the remote address that the socket is connected to.

The connect method will connect this socket to a remote address. This method will fail if the socket is not connected.

§Return

On success, the number of bytes sent is returned, otherwise, the encountered error is returned.

Source

pub fn send_to<'a, 'b>( &'b self, buffer: &'a [u8], to: SocketAddr, ) -> SendToFut<'a, 'b>

Sends data on the socket to the given address. On success, returns the number of bytes written.

Source

pub fn connect(&self, addr: SocketAddr) -> Result<()>

Connects the UDP socket setting the default destination for send() and limiting packets that are read via recv from the address specified in addr.

Source

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

Returns the local address of this socket.

Source

pub async fn close(&self)

Closes the socket, and waits for the underlying libc::close call to be finished.

Source

pub fn is_closed(&self) -> bool

Check if this socket is closed.

Source

pub fn poll_writable(&self, cx: &mut Context<'_>) -> Poll<Result<()>>

Poll for writable

Source

pub fn try_send_quinn(&self, transmit: &Transmit<'_>) -> Result<()>

Send a quinn based Transmit.

Source

pub fn poll_send_quinn( &self, cx: &mut Context<'_>, transmit: &Transmit<'_>, ) -> Poll<Result<()>>

poll send a quinn based Transmit.

Source

pub fn poll_recv_quinn( &self, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Poll<Result<usize>>

quinn based poll_recv

Source

pub fn create_sender(self: Arc<Self>) -> UdpSender

Creates a UdpSender sender.

Source

pub fn may_fragment(&self) -> bool

Whether transmitted datagrams might get fragmented by the IP layer

Returns false on targets which employ e.g. the IPV6_DONTFRAG socket option.

Source

pub fn max_gso_segments(&self) -> usize

The maximum amount of segments which can be transmitted if a platform supports Generic Send Offload (GSO).

This is 1 if the platform doesn’t support GSO. Subject to change if errors are detected while using GSO.

Source

pub fn gro_segments(&self) -> usize

The number of segments to read when GRO is enabled. Used as a factor to compute the receive buffer size.

Returns 1 if the platform doesn’t support GRO.

Trait Implementations§

Source§

impl Debug for UdpSocket

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for UdpSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more