summaryrefslogtreecommitdiff
path: root/src/sys/socket/mod.rs
diff options
context:
space:
mode:
authorToby DiPasquale <toby@cbcg.net>2020-11-25 02:47:27 -0500
committerToby DiPasquale <toby@cbcg.net>2020-11-27 21:49:41 -0500
commitaef3068c1d688cab8b5fbbd51534fd4d5c4ead53 (patch)
tree85a95f049b93d956149f1f615740dd1ff2846d9e /src/sys/socket/mod.rs
parent1794a471483800e0a6be0a7aac1165e916b16797 (diff)
downloadnix-aef3068c1d688cab8b5fbbd51534fd4d5c4ead53.zip
Fix recvmmsg(2) implementation
There were two problems discovered with the `recvmmsg(2)` implementation that this changeset attempts to fix: 1. As mentioned in nix-rust/issues/1325, `recvmmsg(2)` can return fewer messages than requested, and 2. Passing the return value of `recvmmsg(2)` as the number of bytes in the messages received is incorrect. This changeset incorporates the proposed fix from nix-rust/issues/1325, as well as passing the correct value (`mmsghdr.msg_len`) for the number of bytes in a given message.
Diffstat (limited to 'src/sys/socket/mod.rs')
-rw-r--r--src/sys/socket/mod.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 3bb96074..a4f599c1 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -1217,17 +1217,18 @@ pub fn recvmmsg<'a, I>(
let ret = unsafe { libc::recvmmsg(fd, output.as_mut_ptr(), output.len() as _, flags.bits() as _, timeout) };
- let r = Errno::result(ret)?;
+ let _ = Errno::result(ret)?;
Ok(output
.into_iter()
+ .take(ret as usize)
.zip(addresses.iter().map(|addr| unsafe{addr.assume_init()}))
.zip(results.into_iter())
.map(|((mmsghdr, address), (msg_controllen, cmsg_buffer))| {
unsafe {
read_mhdr(
mmsghdr.msg_hdr,
- r as isize,
+ mmsghdr.msg_len as isize,
msg_controllen,
address,
cmsg_buffer