pub struct PacketReceiver { /* private fields */ }Expand description
Receiver task for handling inbound packets
Implementations§
Source§impl PacketReceiver
impl PacketReceiver
Sourcepub async fn recv(&mut self) -> Result<(Bytes, SocketAddr)>
pub async fn recv(&mut self) -> Result<(Bytes, SocketAddr)>
Receive the next packet.
Routes through tokio’s recv_buf_from(&mut BufMut) per
crypto-session perf #130. The legacy
resize(MAX_PACKET_SIZE, 0) + recv_from(&mut [u8]) shape
zero-filled ~1500 bytes per packet just for the kernel to
overwrite them on the next syscall — pure wasted memset
bandwidth at packet rate. recv_buf_from writes directly
into the BytesMut’s spare capacity using BufMut::chunk_mut,
so the kernel’s bytes are the first writers and no
pre-init is needed.
clear() + reserve(MAX_PACKET_SIZE) returns the buffer
to length 0 while keeping the existing allocation; the
reserve is a no-op once steady-state capacity is reached.
The freeze() at the end transfers ownership of the
initialized prefix to the returned Bytes; split()
leaves the underlying allocation behind for the next call
to reuse via reserve.
Sourcepub async fn recv_parsed(&mut self) -> Result<Option<ParsedPacket>>
pub async fn recv_parsed(&mut self) -> Result<Option<ParsedPacket>>
Parse the next packet