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 MsgHdrMut::control_len to get how much of control buffer was filled. #505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib.rs
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
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
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