Skip to content

Commit fc41670

Browse files
committed
Add Socket::recvmsg
1 parent 008603d commit fc41670

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/socket.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use std::os::windows::io::{FromRawSocket, IntoRawSocket};
2121
use std::time::Duration;
2222

2323
use crate::sys::{self, c_int, getsockopt, setsockopt, Bool};
24+
#[cfg(all(unix, not(target_os = "redox")))]
25+
use crate::MsgHdrMut;
2426
use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type};
2527
#[cfg(not(target_os = "redox"))]
2628
use crate::{MaybeUninitSlice, MsgHdr, RecvFlags};
@@ -627,6 +629,19 @@ impl Socket {
627629
sys::peek_sender(self.as_raw())
628630
}
629631

632+
/// Receive a message from a socket using a message structure.
633+
///
634+
/// This is not supported on Windows as calling `WSARecvMsg` (the `recvmsg`
635+
/// equivalent) is not straight forward on Windows. See
636+
/// <https://github.com/microsoft/Windows-classic-samples/blob/7cbd99ac1d2b4a0beffbaba29ea63d024ceff700/Samples/Win7Samples/netds/winsock/recvmsg/rmmc.cpp>
637+
/// for an example (in C++).
638+
#[doc = man_links!(recvmsg(2))]
639+
#[cfg(all(unix, not(target_os = "redox")))]
640+
#[cfg_attr(docsrs, doc(cfg(all(unix, not(target_os = "redox")))))]
641+
pub fn recvmsg(&self, msg: &mut MsgHdrMut<'_, '_, '_>, flags: sys::c_int) -> io::Result<usize> {
642+
sys::recvmsg(self.as_raw(), msg, flags)
643+
}
644+
630645
/// Sends data on the socket to a connected peer.
631646
///
632647
/// This is typically used on TCP sockets or datagram sockets which have

src/sys/unix.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,11 @@ pub(crate) fn recv_from_vectored(
10101010
}
10111011

10121012
#[cfg(not(target_os = "redox"))]
1013-
fn recvmsg(fd: Socket, msg: &mut MsgHdrMut<'_, '_, '_>, flags: c_int) -> io::Result<usize> {
1013+
pub(crate) fn recvmsg(
1014+
fd: Socket,
1015+
msg: &mut MsgHdrMut<'_, '_, '_>,
1016+
flags: c_int,
1017+
) -> io::Result<usize> {
10141018
syscall!(recvmsg(fd, &mut msg.inner, flags)).map(|n| n as usize)
10151019
}
10161020

src/sys/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use windows_sys::Win32::Networking::WinSock::{
2828
};
2929
use windows_sys::Win32::System::Threading::INFINITE;
3030

31-
use crate::{MsgHdr, MsgHdrMut, RecvFlags, SockAddr, TcpKeepalive, Type};
31+
use crate::{MsgHdr, RecvFlags, SockAddr, TcpKeepalive, Type};
3232

3333
#[allow(non_camel_case_types)]
3434
pub(crate) type c_int = std::os::raw::c_int;

0 commit comments

Comments
 (0)