-
Notifications
You must be signed in to change notification settings - Fork 668
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
recvmmsg is strange #1602
Comments
I don't 100% understand. In what way does "test case seem to cheat"? And I'm also not sure what you're asking for. Are you asking to eliminate the |
Words are hard, sorry about that :) So test defines data to send at line 422, performs the recvmmsg call at 482 Line 442 in 515e99b
and then checks the results in two separate actions: for RecvMsg { address, bytes, .. } in res.into_iter() {
assert_eq!(AddressFamily::Inet, address.unwrap().family());
assert_eq!(DATA.len(), bytes);
}
for buf in &receive_buffers {
assert_eq!(&buf[..DATA.len()], DATA);
}
Cheating: Note that the second check uses So two changes:
Also I'm not asking you to make the changes, just to confirm if my understanding is correct - I'll make a patch myself. |
I can refer to this problem. When using The problem is the use of a single lifetime to bind the whole pub struct RecvMmsgData<'a, 'b, I>
where I: AsRef<[IoVec<&'b mut [u8]>]> + 'b,
{
pub iov: I,
pub cmsg_buffer: Option<&'a mut Vec<u8>>,
pub phantom: PhantomData<&'b ()>,
}
pub fn recvmmsg<'c, 'a: 'c, 'b: 'c, I>(
fn: RawFd,
data: impl std::iter::IntoIterator<Item=&'c mut RecvMmsgData<'a, 'b, I>,
IntoIter=impl ExactSizeIterator + Iterator<Item=&'c mut RecvMmsgData<'a, 'b, I>>>,
flags: MsgFlags,
timeout: Option<crate::sys::time::TimeSpec>
) -> Result<Vec<RecvMsg<'a>>>
where I: AsRef<[IoVec<&'b mut [u8]>]> + 'b,
{
[...]
} This will do, but is a breaking change. |
The sendmmsg and recvmmsg API is really hard to use |
Amen. recvmmsg is one of those things that makes me wish I'd become a day laborer instead of a programmer. Well, almost. But @n47h4n13l 's proposal sounds ok. Have you actually implemented it yet? Would you be willing to make a PR? |
1744: reimplement sendmmsg/recvmmsg with better API r=rtzoeller a=pacak Motivation is explained in #1602, new version allows to receive data without performing allocations inside the receive loop and to use received data without extra copying. This pull request contains a breaking change to API `recvmmsg` (obviously) and also affects `recvmsg` - new version does not set length of control message buffer if one is passed. Later change can be avoided with a bit more copy-paste. Fixes #1602 Co-authored-by: Michael Baikov <[email protected]>
recvmmsg
takesdata
which is almost but not quite a mutable array reference to prepared buffers and returns a vector ofRecvMsg<'a>
which contains a reference todata
, at least for as long as lifetimes are concerned. At this moment information about received packets is contained in two places: whatever is used to createdata
- payload we got and a vector thatrecvmmsg
returns. To do anything with a packet we need both - payload fromdata
and size of payload from the vector, but as long as lifetimes are concerned we can't do anything todata
until we release the reference to the vector.Even the test case seem to cheat here by size of the data sent rather than data received and changing it to do something similar to this
results in
And it seems like the only way to actually use it is to extract anything from the resulting vector first (by doing allocations and not holding any references to it), drop it and only then process the actual payload - more allocations, bigger and slower code which you are probably trying to avoid by using
recvmmsg
in the first place.So questions:
The text was updated successfully, but these errors were encountered: