-
Notifications
You must be signed in to change notification settings - Fork 265
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
Buf::chunks_vectored() is wrong if chunk() isn't the whole buf #701
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The design of
Buf::chunks_vectored()
does not account for an implementation that returns a partial slice inchunk()
and doesn't overridechunks_vectored()
to be the full thing. It's assumed that if you have a composite buf, such asChain
, that you can just fill theIoSlice
s with both.First reported in hyperium/hyper#3650
Example
Interestingly, the documentation for
chunks_vectored
even declares a guarantee that likely cannot be upheld:Solutions
With the way the function signature is designed, I don't see a cheap way to check after a call if it really represents all of the
buf
.An expensive solution would be to provide a helper function that compares
remaining()
with what was placed in the&mut [IoSlice]
, and only if true, pass the rest of the slices to the next buffer in the list.Another option I can think of is to design a whole new function,
chunks_vectored_done_right()
, with arguments/return types that prevent making that mistake, deprecating the existing method, and probably changing the default to use the expensive solution anyways.The text was updated successfully, but these errors were encountered: