Skip to content

Commit

Permalink
Don't use MsgHdr for recvmsg
Browse files Browse the repository at this point in the history
Instead we'll create a separate MsgHdrMut for recvmsg, similar to
IoSlice and IoSliceMut.
  • Loading branch information
Thomasdezeeuw committed Jun 8, 2023
1 parent 457d326 commit 49b844f
Showing 1 changed file with 4 additions and 30 deletions.
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

0 comments on commit 49b844f

Please sign in to comment.