-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Improve documentation of read_vectored and write_vectored #74825
Comments
cc @ueno |
Much like with The documentation also says this:
|
Hey @nagisa, thanks for this! I agree with what you say, it's just that the behaviour is inconsistent between the platforms. On macOS/Linux for instance, |
I should also add, that if this is the intended behaviour on Windows, then that's fine but it should be documented more clearly. This line in the docs makes it sound as if this should return all slices filled:
So I guess a sentence on expected differences between hosts would go a long way here. |
Any platform is free to fill as much or as little of your provided buffer(s) as they want, and does not have to be consistent about it. It is your responsibility, regardless of platform, to check how many bytes were read and proceed accordingly. That said, Windows does not have vectored read/write operations for anything other than sockets, so aside from sockets Better documentation on this would be a good idea for sure. |
@retep998 agreed! Thanks for the input and explanation. I’ll be more than happy to help documenting this, but I’m wondering what the best next steps wrt this issue are. Given that this is not a bug I guess it’ll make sense to close this issue. If you feel otherwise, lemme know and I’ll reopen or feel free to do this yourself! |
Generally when an issue turns out to be not a bug, but docs can be improved, the issue is left open but tags changed like so. |
Any idea on how to improve the docs for this? |
Maybe something like the |
Do you think these are good example for Vectored I/O? I try my best to show a good use case, feel free to give any suggestions. use std::io::{IoSlice, Write};
let mut writer = Vec::new();
let buf = [
IoSlice::new(b"GET "),
IoSlice::new(&[47]),
IoSlice::new(b" HTTP/1.1"),
];
assert_eq!(writer.write_vectored(&buf).unwrap(), 14);
assert_eq!(writer, b"GET / HTTP/1.1"); use std::io::{IoSliceMut, Read};
// Capn' Proto recommends framing in 4 bytes
let reader = vec![0_u8, 0, 0, 0, 1, 2, 3, 4];
let mut buf = vec![0; 8];
let mut iovecs = buf
.chunks_exact_mut(4)
.map(IoSliceMut::new)
.collect::<Vec<_>>();
assert_eq!(reader.as_slice().read_vectored(&mut iovecs).unwrap(), 8);
assert_eq!(buf, reader); I think from the documentation side we need to add both examples and OS-specific behavior for this (I don't know much about these for Vectored I/O). |
Today I just happened to be reading the documentation for write_vectored, which currently states:
This appears to describe a trait contract, and then immediately violate it! Even after reading this thread, I am left moderately confused about the purpose of this method or the obligations of a Write implementor in relation to it. Better docs are definitely in order. |
Apologies if this is a duplicate, but I couldn't find a mention of this anywhere.
A simple snippet like the following:
will incorrectly only populate the first
IoSliceMut
and exit prematurely on Windows. (See here for a full snippet).See bytecodealliance/wasmtime#2070 for a downstream issue.
The text was updated successfully, but these errors were encountered: