Skip to content

Commit

Permalink
Add MsgHdrMut::control_len to get how much of control buffer was filled.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz authored and Thomasdezeeuw committed Apr 16, 2024
1 parent c93cdcc commit 21ba660
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,15 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
pub fn flags(&self) -> RecvFlags {
sys::msghdr_flags(&self.inner)
}

/// Gets the length of the control buffer.
///
/// Can be used to determine how much, if any, of the control buffer was filled by `recvmsg`.
///
/// Corresponds to `msg_controllen` on Unix and `Control.len` on Windows.
pub fn control_len(&self) -> usize {
sys::msghdr_control_len(&self.inner)
}
}

#[cfg(not(target_os = "redox"))]
Expand Down
5 changes: 5 additions & 0 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags {
RecvFlags(msg.msg_flags)
}

#[cfg(not(target_os = "redox"))]
pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize {
msg.msg_controllen as _
}

/// Unix only API.
impl SockAddr {
/// Constructs a `SockAddr` with the family `AF_VSOCK` and the provided CID/port.
Expand Down
4 changes: 4 additions & 0 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags {
RecvFlags(msg.dwFlags as c_int)
}

pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize {
msg.Control.len as _
}

fn init() {
static INIT: Once = Once::new();

Expand Down

0 comments on commit 21ba660

Please sign in to comment.