Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Socket::{send,recv}msg and MsgHdr(Mut) #447

Merged
merged 10 commits into from
Jun 8, 2023
Prev Previous commit
Next Next commit
Don't use MsgHdr for recvmsg
Instead we'll create a separate MsgHdrMut for recvmsg, similar to
IoSlice and IoSliceMut.
  • Loading branch information
Thomasdezeeuw committed Jun 3, 2023
commit c8056d5200a348bfe674075e06f4e69930f90468
34 changes: 4 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,15 @@ impl TcpKeepalive {
}
}

/// Configuration of a `{send,recv}msg` system call.
/// Configuration of a `sendmsg(2)` system call.
///
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows.
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`]
/// for the variant used by `recvmsg(2)`.
#[cfg(not(target_os = "redox"))]
pub struct MsgHdr<'addr, 'bufs, 'control> {
inner: sys::msghdr,
#[allow(clippy::type_complexity)]
_lifetimes: PhantomData<(&'addr SockAddr, &'bufs [&'bufs [u8]], &'control [u8])>,
_lifetimes: PhantomData<(&'addr SockAddr, &'bufs IoSlice<'bufs>, &'control [u8])>,
}

#[cfg(not(target_os = "redox"))]
Expand All @@ -600,15 +601,6 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
self
}

/// Set the mutable address (name) of the message. Same as [`with_addr`],
/// but with a mutable address.
///
/// [`with_addr`]: MsgHdr::with_addr
pub fn with_addr_mut(mut self, addr: &'addr mut SockAddr) -> Self {
sys::set_msghdr_name(&mut self.inner, addr);
self
}

/// Set the buffer(s) of the message.
///
/// Corresponds to setting `msg_iov` and `msg_iovlen` on Unix and `lpBuffers`
Expand All @@ -619,15 +611,6 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
self
}

/// Set the mutable buffer(s) of the message. Same as [`with_buffers`], but
/// with mutable buffers.
///
/// [`with_buffers`]: MsgHdr::with_buffers
pub fn with_buffers_mut(mut self, bufs: &'bufs mut [MaybeUninitSlice<'bufs>]) -> Self {
sys::set_msghdr_iov(&mut self.inner, bufs.as_mut_ptr().cast(), bufs.len());
self
}

/// Set the control buffer of the message.
///
/// Corresponds to setting `msg_control` and `msg_controllen` on Unix and
Expand All @@ -638,15 +621,6 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
self
}

/// Set the mutable control buffer of the message. Same as [`with_control`],
/// but with a mutable buffers.
///
/// [`with_control`]: MsgHdr::with_control
pub fn with_control_mut(mut self, buf: &'control mut [u8]) -> Self {
sys::set_msghdr_control(&mut self.inner, buf.as_mut_ptr().cast(), buf.len());
self
}

/// Set the flags of the message.
///
/// Corresponds to setting `msg_flags` on Unix and `dwFlags` on Windows.
Expand Down