Skip to main content

transfer_session_datagram

Function transfer_session_datagram 

pub async fn transfer_session_datagram<A, B>(
    a: &mut A,
    b: &mut B,
    max_buffer: usize,
    abort_stream: Option<AbortRegistration>,
) -> Result<(usize, usize), Error>
where A: AsyncRead + AsyncWrite + Unpin + ?Sized, B: AsyncRead + AsyncWrite + Unpin + ?Sized,
Expand description

Datagram-boundary-preserving variant of transfer_session for UDP session bridges.

Both directions of the bridge preserve datagram boundaries: each read (one UDP datagram from the stream, or one reassembled frame from the session) is written to the other side separately and flushed before the next read, instead of coalescing several reads into one oversized write under backpressure (which the segmenter can no longer split back apart). This preserves datagram boundaries; it does not guarantee exactly one write per datagram, since a single datagram may still span several writes if the writer accepts partial writes. See hoprnet#8421.

Precondition: both sides must yield at most one datagram/frame per poll_read — the UDP StreamReader and the session’s frame reader both do. A reader that returned two datagrams in one read would still write them together.