-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for vectored IO support #58452
Comments
@sfackler is this for an open PR or pending RFC? I can't find anything relevant. |
Introduced in #58357 |
I'd like to at least investigate the DST solution before we stabilize to see what would be the blockers. It would be a pleasant outcome to have these types written |
Looked into what making this into a DST would entail; it looks like what these need is some way to specify the metadata type, because on some platforms the metadata is not the same ABI as a |
You also need control over the ordering - the length field comes before the pointer in a WSABUF. |
Oh jeez, I'm not sure that we can accomplish having a |
Yeah. The iovec crate hacked around this by having the DST be a slice where the length was secretly the pointer and the pointer was secretly the length, but it's then unsound to have an empty iovec. It just barely happens to work. If we targeted a slightly weirder platform with e.g. a 32 byte length and 4-byte aligned pointers we'd be SOL. |
I mean isn't that hack broken as soon as someone writes |
There is a test in tcp: let a = [];
let b = [10];
let c = [11, 12];
t!(s1.write_vectored(&[IoVec::new(&a), IoVec::new(&b), IoVec::new(&c)]));
let mut buf = [0; 4];
let len = t!(s2.read(&mut buf));
// some implementations don't support writev, so we may only write the first buffer
if len == 1 {
assert_eq!(buf, [10, 0, 0, 0]);
} else {
assert_eq!(len, 3);
assert_eq!(buf, [10, 11, 12, 0]);
} However, the first buffer is the empty buffer, so some platforms don't write anything at all! From pub fn write_vectored(&self, buf: &[IoVec<'_>]) -> io::Result<usize> {
let buf = match buf.get(0) {
Some(buf) => buf,
None => return Ok(0),
};
self.write(buf)
} The documentation for
I'm not exactly sure what the expected behavior here is. |
Oh, oops, I forgot to fix the SGX implementation. It should find the first nonempty buffer: https://github.com/rust-lang/rust/blob/master/src/libstd/io/mod.rs#L535-L537 |
I plan on issuing breaking change releases of a bunch of crates around the time async / await is stabilized. This will include crates that currently depend on |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
As of this writing, these are the APIs in pub struct IoVec<'a>(…);
pub struct IoVecMut<'a>(…);
impl<'a> fmt::Debug for IoVec<'a> {…}
impl<'a> fmt::Debug for IoVecMut<'a> {…}
impl<'a> IoVec<'a> {
pub fn new(buf: &'a [u8]) -> Self {…}
}
impl<'a> IoVecMut<'a> {
pub fn new(buf: &'a mut [u8]) -> Self {…}
}
impl<'a> Deref for IoVec<'a> {
type Target = [u8];
}
impl<'a> Deref for IoVecMut<'a> {
type Target = [u8];
}
impl<'a> DerefMut for IoVecMut<'a> {…}
pub trait Write {
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result<usize> {…}
}
pub trait Read {
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result<usize> {…}
} |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I wish we could have these types be written as DSTs, but it doesn't seem realistic (given that the pointer is the second value on some platforms) or worth blocking on. |
@rfcbot concern name I want to raise a question actually: is iovec the right name for these types? We've just taken the name used by UNIX, which is something in the past we moved away from (renaming the various fs functions for example). In particular, I think IoVec is somewhat confusing because in Rust its pretty established that Vec specifically means our heap allocated buffer type. Perhaps it would be wise to rename them? |
That's true! @withoutboats do you have ideas for alternative names? I think one possibility is |
|
But yeah, something that indicates that it's a slice seems like a good idea. |
+1 for I’m not sure how
… it’s each item of the “outer” array that’s called |
|
I've personally always been slightly confused with the gather/scatter terminology although if I sit down and think hard about it then it makes sense. I'm warming up personally to |
Yea I was thinking either I'd propose we change the name to ioslice and also make sure the docs for the two types are clear that they correspond to iovec on unix and wsabuf on windows. |
👍 The docs do already mention the iovec/WSABUF correspondence, but it could probably be called out better: https://doc.rust-lang.org/std/io/struct.IoVec.html |
@rfcbot resolve name |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
If the type does not use Vec in the name, should the fns use a different suffix than vectored? |
|
I would disagree that we need to rename the |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
So it sounds like the changes we want to make are I'll make a stabilization PR if so. |
That was my read on this as well! And thanks @sfackler! |
This renames `std::io::IoVec` to `std::io::IoSlice` and `std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes `std::io::IoSlice`, `std::io::IoSliceMut`, `std::io::Read::read_vectored`, and `std::io::Write::write_vectored`. Closes rust-lang#58452
Stabilized vectored IO This renames `std::io::IoVec` to `std::io::IoSlice` and `std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes `std::io::IoSlice`, `std::io::IoSliceMut`, `std::io::Read::read_vectored`, and `std::io::Write::write_vectored`. Closes rust-lang#58452 r? @alexcrichton
Would it be worth to add |
This covers
Read::read_vectored
,Write::write_vectored
,IoVec
, andIoVecMut
.The text was updated successfully, but these errors were encountered: