Skip to content

buffer: add helper function for implementing Write::write_vectored#48366

Merged
jkarneges merged 4 commits into
mainfrom
jkarneges/vectored-helper
Jun 15, 2026
Merged

buffer: add helper function for implementing Write::write_vectored#48366
jkarneges merged 4 commits into
mainfrom
jkarneges/vectored-helper

Conversation

@jkarneges

@jkarneges jkarneges commented Jun 13, 2026

Copy link
Copy Markdown
Member

The default implementation of Write::write_vectored conservatively calls write with the first slice only. This can lead to surprising behavior when developing code that performs vectored writes against memory/fake destinations that don't implement write_vectored themselves, and only the first slice shows up.

This PR adds a function that calls write on all provided slices, which can be a more convenient default, at least for in-memory destinations where the call costs are cheap. It then uses it in a couple of our buffer types.

@jkarneges jkarneges force-pushed the jkarneges/vectored-helper branch from d71c19d to 9430f42 Compare June 13, 2026 00:56
@jkarneges jkarneges requested a review from a team June 13, 2026 01:18
@jkarneges

Copy link
Copy Markdown
Member Author

Tweaked the implementation a little bit. Previously, if an error is encountered, partial progress would be reported only when the error kind is WriteZero. However, I think we should always report partial progress when an error is encountered, regardless of type (with the exception of Interrupted, for which retrying is idiomatic), otherwise that information is lost. Of course, whenever we report partial progress in response to an error then we are losing the error information instead, but in general the next write attempt should trigger the same error again.

Note that these distinctions aren't meaningful when used directly by memory buffers, which is all we are doing today. Just making the impl a little more robust in case it finds its way into a middleware atop a socket or something.

@jkarneges jkarneges merged commit 832a946 into main Jun 15, 2026
19 checks passed
@jkarneges jkarneges deleted the jkarneges/vectored-helper branch June 15, 2026 20:13
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.

2 participants