Skip to main content

DatagramSocket

Trait DatagramSocket 

pub trait DatagramSocket: Socket + Debug {
    type Sender: DatagramSender;

    // Required methods
    fn create_sender(&self) -> Self::Sender;
    fn poll_recv(
        &mut self,
        cx: &mut Context<'_>,
        buffers: &mut [IoSliceMut<'_>],
        metadata: &mut [DatagramMetadata],
    ) -> Poll<Result<usize, DatagramError>>;
    fn capabilities(&self) -> DatagramCapabilities;
}
Available on crate features std and udp only.
Expand description

Receive side of an asynchronous packet-oriented datagram socket.

This deliberately does not implement stream-oriented AsyncRead or AsyncWrite: a successful operation always preserves datagram boundaries, and a zero-length datagram is data rather than end-of-file.

Async convenience methods live on DatagramSocketExt. Receive polling is a single-logical-consumer operation: at most one task may poll a socket’s receive side at a time.

Required Associated Types§

type Sender: DatagramSender

Independently wakeable send handle created by this socket.

Required Methods§

fn create_sender(&self) -> Self::Sender

Create a send handle with independent readiness registration.

Separate handles let several tasks wait for send readiness without one task replacing another task’s waker.

fn poll_recv( &mut self, cx: &mut Context<'_>, buffers: &mut [IoSliceMut<'_>], metadata: &mut [DatagramMetadata], ) -> Poll<Result<usize, DatagramError>>

Receive one or more datagrams, or register for readiness.

buffers and metadata must have equal, non-zero lengths. On success, the returned count is in 1..=buffers.len(), and only that many entries have been filled. Cancelling a pending call never consumes a datagram.

fn capabilities(&self) -> DatagramCapabilities

Current runtime-detected capabilities.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§