Skip to content
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

add specialized Buf::chunks_vectored for Take #617

Merged
merged 8 commits into from
Jan 13, 2025

Conversation

srijs
Copy link
Contributor

@srijs srijs commented Jun 11, 2023

The h2 crate uses Take around the data frames to enforce a maximum frame size, which breaks vectored writes since Take doesn't provide a specialized chunks_vectored that calls the underlying chunks_vectored.

To make this work with truncating individual IoSlices, I needed to resort to a tiny bit of unsafe code. There is a PR open (rust-lang/rust#111277) which will alleviate the need for it, but that hasn't landed yet (so unlikely to be stable any time soon).

An alternative could be to just remove rather than truncate any IoSlice that crosses the limit threshold, which could be accomplished without any unsafe code. However, that might break the following guarantee documented on chunks_vectored: "If chunk_vectored does not fill every entry in dst, then dst is guaranteed to contain all remaining slices in `self."

Happy to go either route, let me know what you think!

@srijs
Copy link
Contributor Author

srijs commented Jun 12, 2023

Just noticed this is a duplicate of #476. Don't have a strong opinion here, please feel free to review and merge either :)

@Darksonn Darksonn force-pushed the impl-buf-chunks-vectored-for-take branch from f8ae0bb to 1482c40 Compare January 10, 2025 14:05
@Darksonn
Copy link
Contributor

Thank you. This got lost, sorry about that. I'm rebasing it and tweaking it myself since it's been so long.

src/buf/take.rs Outdated Show resolved Hide resolved
@Darksonn
Copy link
Contributor

The test was failing because this is writing to the extra slots in dst even though they are not being used.

@Darksonn Darksonn force-pushed the impl-buf-chunks-vectored-for-take branch from cf0477b to a9ec05d Compare January 13, 2025 09:04
@Darksonn Darksonn force-pushed the impl-buf-chunks-vectored-for-take branch from 10b5341 to 94e5843 Compare January 13, 2025 09:15
@Darksonn Darksonn enabled auto-merge (squash) January 13, 2025 09:23
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@Darksonn Darksonn merged commit aae4969 into tokio-rs:master Jan 13, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants