-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std::io::Write::write_vectored() to io::stdout() does not produce all expected lines. #68041
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
On nightly this panics with an |
Like |
This behavior does not match the documentation:
|
"final buffer" means the final buffer that was read from, not the last buffer in the input slice. A concrete example of short writes beyond the OS doing that is the default implementation:
|
Would there be opposition to adding write_all_vectored() rather than having everybody implement the same logic of retrying until all data is written? |
I think that would definitely make sense, though the implementation would be pretty tricky. Even more reason that it should be done once though I guess! |
I'll work on writing it.
…On Thu, Jan 9, 2020 at 10:33 AM Steven Fackler ***@***.***> wrote:
I think that would definitely make sense, though the implementation would
be pretty tricky. Even more reason that it should be done once though I
guess!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#68041?email_source=notifications&email_token=AAFSWJOMZWO2OR3ASGQX523Q447THA5CNFSM4KESBSX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIQWNWQ#issuecomment-572614362>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFSWJNS4IP2OXNVEMAQGDDQ447THANCNFSM4KESBSXQ>
.
|
It seems others are working on it in #62726, but are blocked since they can't advance the pointer inside of the pending or partially written |
Here is an example write_all_vectored that works with nightly: fn write_all_vectored(file: &mut File, mut bufs: &mut [IoSlice<'_>]) -> std::io::Result<()> {
while bufs.len() > 0 {
match file.write_vectored(bufs) {
Ok(0) => {
return Err(std::io::Error::new(
std::io::ErrorKind::WriteZero,
"failed to write whole buffer",
));
}
Ok(n) => bufs = IoSlice::advance(bufs, n),
Err(ref e) if e.kind() == std::io::ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
}
Ok(())
} |
That modifies the input slice array, which may or may not be a thing we'd want in an implementation in |
You mean write? |
Er, yeah. |
How do you think it could be done by not modifying the array? |
It could do a non-vectored write to finish off half written buffers, or very carefully swap out the partial buffer with an adjusted one and then fix it up after. |
I think performing a non-vectored write or many of them would not be what the person writing the code intends. For example if I have a million element array of If after the first |
It wouldn't be doing a write for each buffer after the first writev, it would at worst be alternating between the two. |
Lint vectored IO in unused_io_amount lint `read_vectored` & `write_vectored` require handling returned value likewise non-vectored methods. rust-lang/rust#68041 --- changelog: lint vectored IO in `unused_io_amount` lint
When trying to write an array of 8192 IoSlices consisting of "1" followed by "\n" only the first character is written on Mac OS X.
Output:
Just one byte is written:
I expected 4096 pairs of
"1\n"
to be written.Meta
The text was updated successfully, but these errors were encountered: