Skip to content
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

Revert workaround for default async methods, closes #85 #86

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 36 additions & 44 deletions crates/hring-buffet/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,55 +80,47 @@ pub trait WriteOwned {

/// Write a list of buffers, re-trying the write if the kernel does a partial write.
async fn writev_all<B: IoBuf>(&self, list: impl Into<Vec<B>>) -> std::io::Result<()> {
// Workaround for https://github.com/rust-lang/rust/issues/107002,
// remove after https://github.com/rust-lang/rust/pull/107013 is merged
writev_all(self, list.into()).await
}
}
// FIXME: converting into a `Vec` and _then_ into an iterator is silly,
// we can probably find a better function signature here.
let mut list: Vec<_> = list.into().into_iter().map(BufOrSlice::Buf).collect();

/// Write a list of buffers, re-trying the write if the kernel does a partial write.
async fn writev_all<B: IoBuf>(
this: &(impl WriteOwned + ?Sized),
list: Vec<B>,
) -> std::io::Result<()> {
let mut list: Vec<_> = list.into_iter().map(BufOrSlice::Buf).collect();

while !list.is_empty() {
let res;
(res, list) = this.writev(list).await;
let n = res?;

if n == 0 {
return Err(std::io::Error::new(
std::io::ErrorKind::WriteZero,
"write zero",
));
}
while !list.is_empty() {
let res;
(res, list) = self.writev(list).await;
let n = res?;

let mut n = n;
list = list
.into_iter()
.filter_map(|item| {
if n == 0 {
Some(item)
} else {
let item_len = item.len();

if n >= item_len {
n -= item_len;
None
} else {
let item = item.consume(n);
n = 0;
if n == 0 {
return Err(std::io::Error::new(
std::io::ErrorKind::WriteZero,
"write zero",
));
}

let mut n = n;
list = list
.into_iter()
.filter_map(|item| {
if n == 0 {
Some(item)
} else {
let item_len = item.len();

if n >= item_len {
n -= item_len;
None
} else {
let item = item.consume(n);
n = 0;
Some(item)
}
}
}
})
.collect();
assert_eq!(n, 0);
}
})
.collect();
assert_eq!(n, 0);
}

Ok(())
Ok(())
}
}

enum BufOrSlice<B: IoBuf> {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-01-21"
channel = "nightly-2023-02-20"
components = ["llvm-tools-preview"]