-
Notifications
You must be signed in to change notification settings - Fork 691
Fixes UB of recvmmsg
and simplifies signatures of recvmmsg
and sendmmsg
#2120
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
Conversation
ad1a41b
to
78cf0a2
Compare
I've completely disabled the |
d4836e9
to
12b417a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, there's another merge conflict in CHANGELOG. Could you fix that, please?
Done. For the https://gist.github.com/Jan561/1e44db811698d06bb247c30bbe448fc9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your gist there suggests that a different API would be more convenient. This is something that I've been thinking about too. It would look something like this:
struct MsgVec<'a> {
msgvec: Vec<libc::msghdr>,
}
impl<'a> MsgVec<'a> {
fn with_capacity(n: usize) -> Self {...}
fn add<S: SockaddrLike + 'a>(&mut self, to: S, I: [IoSlice<'a>], &mut cmsg: ControlMessage<'a>)
fn reset(&mut self);
}
fn sendmmsg<F>(fd: F, msgvec: MsgVec<'_>, flags: MsgFlags)
where F: AsFd
{}
And you could use it something like this:
let mut msg_vec = MsgVec::with_capacity(2);
msg_vec.add(some_host, &[iovec0, iovec1][..], &[ControlMessage::ScmRights(...)][..]);
sendmmsg(&s, msg_vec);
The general idea being that the add
API keeps related host, data, and control messages together rather than forcing the user to split them into 3 separate arrays. Plus, the MsgVec::reset
method allows reusing storage for a MsgVec
, eliminating the need to allocate on each call of sendmmsg, which was the primary problem of the earlier implementation.
The signature of
recvmmsg
gets changed to:The signature of
sendmmsg
gets changed to:Fixes #2119