@@ -596,11 +596,36 @@ impl Socket {
596
596
/// `peek_from` makes the same safety guarantees regarding the `buf`fer as
597
597
/// [`recv`].
598
598
///
599
+ /// # Note: Datagram Sockets
600
+ /// For datagram sockets, the behavior of this method when `buf` is smaller than
601
+ /// the datagram at the head of the receive queue differs between Windows and
602
+ /// Unix-like platforms (Linux, macOS, BSDs, etc: colloquially termed "*nix").
603
+ ///
604
+ /// On *nix platforms, the datagram is truncated to the length of `buf`.
605
+ ///
606
+ /// On Windows, an error corresponding to `WSAEMSGSIZE` will be returned.
607
+ ///
608
+ /// For consistency between platforms, be sure to provide a sufficiently large buffer to avoid
609
+ /// truncation; the exact size required depends on the underlying protocol.
610
+ ///
611
+ /// If you just want to know the sender of the data, try [`peek_sender`].
612
+ ///
599
613
/// [`recv`]: Socket::recv
614
+ /// [`peek_sender`]: Socket::peek_sender
600
615
pub fn peek_from ( & self , buf : & mut [ MaybeUninit < u8 > ] ) -> io:: Result < ( usize , SockAddr ) > {
601
616
self . recv_from_with_flags ( buf, sys:: MSG_PEEK )
602
617
}
603
618
619
+ /// Retrieve the sender for the data at the head of the receive queue.
620
+ ///
621
+ /// This is equivalent to calling [`peek_from`] with a zero-sized buffer,
622
+ /// but suppresses the `WSAEMSGSIZE` error on Windows.
623
+ ///
624
+ /// [`peek_from`]: Socket::peek_from
625
+ pub fn peek_sender ( & self ) -> io:: Result < SockAddr > {
626
+ sys:: peek_sender ( self . as_raw ( ) )
627
+ }
628
+
604
629
/// Sends data on the socket to a connected peer.
605
630
///
606
631
/// This is typically used on TCP sockets or datagram sockets which have
0 commit comments