Skip to content

Commit

Permalink
Merge pull request #86 from hapsoc/default-methods
Browse files Browse the repository at this point in the history
Revert workaround for default async methods, closes #85
  • Loading branch information
fasterthanlime authored Feb 20, 2023
2 parents 1988666 + 9e6a808 commit 48f89f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
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"]

0 comments on commit 48f89f3

Please sign in to comment.