-
Notifications
You must be signed in to change notification settings - Fork 9
mctp-estack: Support vectored payloads in fragmenter #36
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
Changes from 2 commits
5fb4425
0f1fdc2
4b85d0e
d1650f9
793949a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,57 @@ impl Fragmenter { | |
| let used = max_total - rest.len(); | ||
| SendOutput::Packet(&mut out[..used]) | ||
| } | ||
|
|
||
| pub fn fragment_vectored<'f>( | ||
| &mut self, | ||
| payload: &[&[u8]], | ||
| out: &'f mut [u8], | ||
| ) -> SendOutput<'f> { | ||
| let total_payload_len = | ||
| payload.iter().fold(0, |acc, part| acc + part.len()); | ||
| if total_payload_len < self.payload_used { | ||
| // Caller is passing varying payload buffers | ||
| debug!("varying payload"); | ||
| return SendOutput::failure(Error::BadArgument, self); | ||
| } | ||
|
|
||
| // Require at least MTU buffer size, to ensure that all non-end | ||
| // fragments are the same size per the spec. | ||
| if out.len() < self.mtu { | ||
| debug!("small out buffer"); | ||
| return SendOutput::failure(Error::BadArgument, self); | ||
| } | ||
|
|
||
| // Reserve header space, the remaining buffer keeps being | ||
| // updated in `rest` | ||
| let max_total = out.len().min(self.mtu); | ||
| let (h, mut rest) = out[..max_total].split_at_mut(MctpHeader::LEN); | ||
|
|
||
| // Append type byte | ||
| if self.header.som { | ||
| rest[0] = mctp::encode_type_ic(self.typ, self.ic); | ||
| rest = &mut rest[1..]; | ||
| } | ||
|
|
||
| let remaining_payload_len = total_payload_len - self.payload_used; | ||
| let l = remaining_payload_len.min(rest.len()); | ||
| let (d, rest) = rest.split_at_mut(l); | ||
| crate::util::copy_vectored(payload, self.payload_used, d); | ||
|
||
| self.payload_used += l; | ||
|
|
||
| // Add the header | ||
| if self.payload_used == total_payload_len { | ||
| self.header.eom = true; | ||
| } | ||
| // OK unwrap: seq and tag are valid. | ||
| h.copy_from_slice(&self.header.encode().unwrap()); | ||
|
|
||
| self.header.som = false; | ||
| self.header.seq = (self.header.seq + 1) & mctp::MCTP_SEQ_MASK; | ||
|
|
||
| let used = max_total - rest.len(); | ||
| SendOutput::Packet(&mut out[..used]) | ||
| } | ||
| } | ||
|
|
||
| pub enum SendOutput<'p> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.