Description
recvmmsg
takes data
which is almost but not quite a mutable array reference to prepared buffers and returns a vector of RecvMsg<'a>
which contains a reference to data
, 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 create data
- payload we got and a vector that recvmmsg
returns. To do anything with a packet we need both - payload from data
and size of payload from the vector, but as long as lifetimes are concerned we can't do anything to data
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
for (buf, r) in msgs.iter().zip(res.iter()) {
....
}
results in
cannot borrow `msgs` as immutable because it is also borrowed as mutable
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:
- Is there anything that prevents recvmmsg from accepting an array (or a slice) and producing an iterator with references to this slice to avoid allocations?
- Should produced iterator (or vector) also contain references to payload buffers?