Struct UdpSocket

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

Tokio-compatible UDP socket with some useful specializations.

Unlike a standard tokio UDP socket, this allows ECN bits to be read and written on some platforms.

Implementations§

Source§

impl UdpSocket

Source

pub fn from_std(socket: UdpSocket) -> Result<UdpSocket>

Creates a new UDP socket from a previously created std::net::UdpSocket

Source

pub fn into_std(self) -> Result<UdpSocket>

Source

pub async fn bind<A: ToSocketAddrs>(addr: A) -> Result<UdpSocket>

create a new UDP socket and attempt to bind to addr

Source

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

sets the value of SO_BROADCAST for this socket

Source

pub fn set_gro(&self, enable: bool) -> Result<()>

Opportunistically try to enable GRO support for this socket. This is only supported on Linux platforms.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub async fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>

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

calls underlying tokio send_to

Source

pub fn poll_send_to( &self, cx: &mut Context<'_>, buf: &[u8], target: SocketAddr, ) -> Poll<Result<usize>>

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

calls underlying tokio poll_send_to

Source

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

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

See tokio send

Source

pub async fn poll_send( &self, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

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

See tokio poll_send

Source

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

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

See tokio recv_from

Source

pub fn poll_recv_from( &self, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<SocketAddr>>

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

See tokio poll_recv_from

Source

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

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.

See tokio recv

Source

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

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.

See tokio poll_recv

Source

pub async fn send_mmsg<B: AsPtr<u8>>( &self, state: &UdpState, transmits: &[Transmit<B>], ) -> Result<usize, Error>

Calls syscall sendmmsg. With a given state configured GSO and transmits with information on the data and metadata about outgoing packets.

Utilizes the default batch size (DEFAULT_BATCH_SIZE), and will send no more than that number of messages. The caller must call this fuction again after modifying transmits to continue sending the entire set of messages.

Source

pub async fn send_mmsg_with_batch_size<B: AsPtr<u8>, const BATCH_SIZE: usize>( &self, state: &UdpState, transmits: &[Transmit<B>], ) -> Result<usize, Error>

Calls syscall sendmmsg. With a given state configured GSO and transmits with information on the data and metadata about outgoing packets.

Sends no more than BATCH_SIZE messages. The caller must call this fuction again after modifying transmits to continue sending the entire set of messages. BATCH_SIZE_CAP defines the maximum that will be sent, regardless of the specified BATCH_SIZE

Source

pub async fn send_msg<B: AsPtr<u8>>( &self, state: &UdpState, transmits: Transmit<B>, ) -> Result<usize>

Calls syscall sendmsg. With a given state configured GSO and transmit with information on the data and metadata about outgoing packet.

Source

pub async fn recv_mmsg( &self, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Result<usize>

async version of recvmmsg with compile-time configurable batch size

Source

pub async fn recv_mmsg_with_batch_size<const BATCH_SIZE: usize>( &self, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Result<usize>

Source

pub async fn recv_msg(&self, buf: &mut [u8]) -> Result<RecvMeta>

recv_msg is similar to recv_from but returns extra information about the packet in RecvMeta.

Source

pub fn poll_send_mmsg<B: AsPtr<u8>>( &mut self, state: &UdpState, cx: &mut Context<'_>, transmits: &[Transmit<B>], ) -> Poll<Result<usize>>

calls sendmmsg

Source

pub fn poll_send_mmsg_with_batch_size<B: AsPtr<u8>, const BATCH_SIZE: usize>( &mut self, state: &UdpState, cx: &mut Context<'_>, transmits: &[Transmit<B>], ) -> Poll<Result<usize>>

calls sendmmsg

Source

pub fn poll_send_msg<B: AsPtr<u8>>( &self, state: &UdpState, cx: &mut Context<'_>, transmits: Transmit<B>, ) -> Poll<Result<usize>>

calls sendmsg with compile-time configurable batch size

Source

pub fn poll_recv_msg( &self, cx: &mut Context<'_>, buf: &mut IoSliceMut<'_>, ) -> Poll<Result<RecvMeta>>

calls recvmsg

Source

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

calls recvmmsg

Source

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

calls recvmmsg with compile-time configurable batch size

Source

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

Returns local address this socket is bound to.

Trait Implementations§

Source§

impl AsFd for UdpSocket

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for UdpSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
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> 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