Skip to content

Commit 21ba660

Browse files
tobzThomasdezeeuw
authored andcommitted
Add MsgHdrMut::control_len to get how much of control buffer was filled.
1 parent c93cdcc commit 21ba660

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,15 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
719719
pub fn flags(&self) -> RecvFlags {
720720
sys::msghdr_flags(&self.inner)
721721
}
722+
723+
/// Gets the length of the control buffer.
724+
///
725+
/// Can be used to determine how much, if any, of the control buffer was filled by `recvmsg`.
726+
///
727+
/// Corresponds to `msg_controllen` on Unix and `Control.len` on Windows.
728+
pub fn control_len(&self) -> usize {
729+
sys::msghdr_control_len(&self.inner)
730+
}
722731
}
723732

724733
#[cfg(not(target_os = "redox"))]

src/sys/unix.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,11 @@ pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags {
738738
RecvFlags(msg.msg_flags)
739739
}
740740

741+
#[cfg(not(target_os = "redox"))]
742+
pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize {
743+
msg.msg_controllen as _
744+
}
745+
741746
/// Unix only API.
742747
impl SockAddr {
743748
/// Constructs a `SockAddr` with the family `AF_VSOCK` and the provided CID/port.

src/sys/windows.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags {
215215
RecvFlags(msg.dwFlags as c_int)
216216
}
217217

218+
pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize {
219+
msg.Control.len as _
220+
}
221+
218222
fn init() {
219223
static INIT: Once = Once::new();
220224

0 commit comments

Comments
 (0)