pub struct SendItem<'a> { /* private fields */ }Expand description
A single outbound UDP datagram.
Build with SendItem::new and optionally chain ecn / segment_size
to attach ancillary data.
When segment_size is set and the platform supports it (Linux GSO), the
kernel will segment data into multiple datagrams of segment_size bytes
each (the final segment may be shorter). This allows sending N packets in
a single syscall. On platforms without GSO the same datagrams are produced
by splitting data in user space.
Implementations§
Source§impl<'a> SendItem<'a>
impl<'a> SendItem<'a>
Sourcepub fn new(destination: SocketAddr, data: &'a [u8]) -> Self
pub fn new(destination: SocketAddr, data: &'a [u8]) -> Self
Create a datagram targeting destination with the given data payload.
Address comes first, then data.
Sourcepub fn segment_size(self, segment_size: u16) -> Self
pub fn segment_size(self, segment_size: u16) -> Self
Enable UDP segmentation offload (GSO on Linux). data is split into
consecutive chunks of segment_size bytes and each chunk is sent as a
separate UDP datagram to the same destination (the final chunk may be
shorter).
On Linux with GSO available the kernel performs the segmentation from a
single sendmsg; everywhere else the chunks are emitted as individual
datagrams in user space.
segment_size must be greater than zero: a zero value makes the next
send fail with io::ErrorKind::InvalidInput.