Skip to content

Commit

Permalink
Remove number of sent messages in sendmmsg, because it can be easil…
Browse files Browse the repository at this point in the history
…y retrieved from Vec len. Improve docs
  • Loading branch information
Gleb Pomykalov committed Apr 20, 2020
1 parent 9878123 commit 0557e4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
32 changes: 18 additions & 14 deletions src/sys/socket/mod.rs
Expand Up @@ -811,9 +811,9 @@ pub struct SendMmsgData<'a, I, C>
pub _lt: std::marker::PhantomData<&'a I>,
}

/// An extension of [`sendmsg`] that allows the caller to transmit multiple
/// messages on a socket using a single system call. (This has performance
/// benefits for some applications.).
/// An extension of `sendmsg` that allows the caller to transmit multiple
/// messages on a socket using a single system call. This has performance
/// benefits for some applications.
///
/// Allocations are performed for cmsgs and to build `msghdr` buffer
///
Expand All @@ -823,11 +823,11 @@ pub struct SendMmsgData<'a, I, C>
/// * `data`: Struct that implements `IntoIterator` with `SendMmsgData` items
/// * `flags`: Optional flags passed directly to the operating system.
///
/// Returns tuple, where the first value is number of sent messages, and the second one
/// it a `Vec` with numbers of bytes sent on each appropriate message.
/// # Returns
/// `Vec` with numbers of sent bytes on each sent message.
///
///# References
/// [`sendmmsg`](fn.sendmsg.html)
/// # References
/// [`sendmsg`](fn.sendmsg.html)
#[cfg(any(
target_os = "linux",
target_os = "android",
Expand All @@ -839,7 +839,7 @@ pub fn sendmmsg<'a, I, C>(
fd: RawFd,
data: impl std::iter::IntoIterator<Item=&'a SendMmsgData<'a, I, C>>,
flags: MsgFlags
) -> Result<(usize, Vec<usize>)>
) -> Result<Vec<usize>>
where
I: AsRef<[IoVec<&'a [u8]>]> + 'a,
C: AsRef<[ControlMessage<'a>]> + 'a,
Expand Down Expand Up @@ -888,7 +888,7 @@ pub fn sendmmsg<'a, I, C>(
sent_bytes[i] = initialized_data[i].msg_len as usize;
}

Ok((sent_messages, sent_bytes))
Ok(sent_bytes)
}


Expand All @@ -902,11 +902,11 @@ pub struct RecvMmsgData<'a, I>
pub cmsg_buffer: Option<&'a mut Vec<u8>>,
}

/// An extension of [`recvmsg`] that allows the caller to receive multiple
/// messages from a socket using a single system call. (This has
/// performance benefits for some applications.)
/// An extension of `recvmsg` that allows the caller to receive multiple
/// messages from a socket using a single system call. This has
/// performance benefits for some applications.
///
/// `iov` and `cmsg_buffer` should be constucted similarly to recvmsg
/// `iov` and `cmsg_buffer` should be constructed similarly to `recvmsg`
///
/// Multiple allocations are performed
///
Expand All @@ -922,8 +922,12 @@ pub struct RecvMmsgData<'a, I>
/// * `cmsg_buffer`: Space to receive ancillary data. Should be created by
/// [`cmsg_space!`](macro.cmsg_space.html)
///
/// # Returns
/// A `Vec` with multiple `RecvMsg`, one per received message
///
/// # References
/// [`recvmsg`](fn.recvmsg.html)
/// - [`recvmsg`](fn.recvmsg.html)
/// - [`RecvMsg`](struct.RecvMsg.html)
#[cfg(any(
target_os = "linux",
target_os = "android",
Expand Down
7 changes: 3 additions & 4 deletions test/sys/test_socket.rs
Expand Up @@ -282,13 +282,12 @@ mod recvfrom {
);
}
sendmmsg(s, msgs.iter(), flags)
.map(move |(sent_messages, sent_bytes)| {
assert!(sent_messages >= 1);
assert_eq!(sent_bytes.len(), sent_messages);
.map(move |sent_bytes| {
assert!(sent_bytes.len() >= 1);
for sent in &sent_bytes {
assert_eq!(*sent, m.len());
}
sent_messages
sent_bytes.len()
})
});
// UDP sockets should set the from address
Expand Down

0 comments on commit 0557e4a

Please sign in to comment.