Skip to content

Commit

Permalink
Even more.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Sep 15, 2023
1 parent b9adf78 commit e6f651e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
46 changes: 27 additions & 19 deletions crates/wasi/src/preview2/host/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ impl<T: WasiView + Sync> streams::HostInputStream for T {

pub mod sync {
use crate::preview2::{
bindings::io::streams::{self as async_streams, Host as AsyncHost},
bindings::io::streams::{
self as async_streams, HostInputStream as AsyncHostInputStream,
HostOutputStream as AsyncHostOutputStream,
},
bindings::sync_io::io::poll::Pollable,
bindings::sync_io::io::streams::{self, InputStream, OutputStream},
host::io::sync::streams::{HostInputStream, HostOutputStream},
Expand Down Expand Up @@ -495,12 +498,12 @@ pub mod sync {

impl<T: WasiView + Sync> HostOutputStream for T {
fn drop(&mut self, stream: Resource<OutputStream>) -> anyhow::Result<()> {
AsyncHost::drop(self, stream)
AsyncHostOutputStream::drop(self, stream)
}

fn check_write(&mut self, stream: Resource<OutputStream>) -> Result<u64, streams::Error> {
Ok(in_tokio(async {
AsyncHost::check_write(self, stream).await
AsyncHostOutputStream::check_write(self, stream).await
})?)
}
fn write(
Expand All @@ -509,7 +512,7 @@ pub mod sync {
bytes: Vec<u8>,
) -> Result<(), streams::Error> {
Ok(in_tokio(async {
AsyncHost::write(self, stream, bytes).await
AsyncHostOutputStream::write(self, stream, bytes).await
})?)
}
fn blocking_write_and_flush(
Expand All @@ -518,7 +521,7 @@ pub mod sync {
bytes: Vec<u8>,
) -> Result<(), streams::Error> {
Ok(in_tokio(async {
AsyncHost::blocking_write_and_flush(self, stream, bytes).await
AsyncHostOutputStream::blocking_write_and_flush(self, stream, bytes).await
})?)
}
fn blocking_write_zeroes_and_flush(
Expand All @@ -527,31 +530,33 @@ pub mod sync {
len: u64,
) -> Result<(), streams::Error> {
Ok(in_tokio(async {
AsyncHost::blocking_write_zeroes_and_flush(self, stream, len).await
AsyncHostOutputStream::blocking_write_zeroes_and_flush(self, stream, len).await
})?)
}
fn subscribe(
&mut self,
stream: Resource<OutputStream>,
) -> anyhow::Result<Resource<Pollable>> {
AsyncHost::subscribe_to_output_stream(self, stream)
AsyncHostOutputStream::subscribe(self, stream)
}
fn write_zeroes(
&mut self,
stream: Resource<OutputStream>,
len: u64,
) -> Result<(), streams::Error> {
Ok(in_tokio(async {
AsyncHost::write_zeroes(self, stream, len).await
AsyncHostOutputStream::write_zeroes(self, stream, len).await
})?)
}

fn flush(&mut self, stream: Resource<OutputStream>) -> Result<(), streams::Error> {
Ok(in_tokio(async { AsyncHost::flush(self, stream).await })?)
Ok(in_tokio(async {
AsyncHostOutputStream::flush(self, stream).await
})?)
}
fn blocking_flush(&mut self, stream: Resource<OutputStream>) -> Result<(), streams::Error> {
Ok(in_tokio(async {
AsyncHost::blocking_flush(self, stream).await
AsyncHostOutputStream::blocking_flush(self, stream).await
})?)
}

Expand All @@ -561,7 +566,7 @@ pub mod sync {
src: Resource<InputStream>,
len: u64,
) -> anyhow::Result<Result<(u64, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::splice(self, src, dst, len).await }).map(xform)
in_tokio(async { AsyncHostOutputStream::splice(self, dst, src, len).await }).map(xform)
}

fn blocking_splice(
Expand All @@ -570,60 +575,63 @@ pub mod sync {
src: Resource<InputStream>,
len: u64,
) -> anyhow::Result<Result<(u64, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::blocking_splice(self, src, dst, len).await }).map(xform)
in_tokio(async { AsyncHostOutputStream::blocking_splice(self, dst, src, len).await })
.map(xform)
}

fn forward(
&mut self,
dst: Resource<OutputStream>,
src: Resource<InputStream>,
) -> anyhow::Result<Result<(u64, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::forward(self, src, dst).await }).map(xform)
in_tokio(async { AsyncHostOutputStream::forward(self, dst, src).await }).map(xform)
}
}

impl<T: WasiView + Sync> HostInputStream for T {
fn drop(&mut self, stream: Resource<InputStream>) -> anyhow::Result<()> {
AsyncHost::drop(self, stream)
AsyncHostInputStream::drop(self, stream)
}

fn read(
&mut self,
stream: Resource<InputStream>,
len: u64,
) -> anyhow::Result<Result<(Vec<u8>, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::read(self, stream, len).await }).map(xform)
in_tokio(async { AsyncHostInputpStream::read(self, stream, len).await }).map(xform)
}

fn blocking_read(
&mut self,
stream: Resource<InputStream>,
len: u64,
) -> anyhow::Result<Result<(Vec<u8>, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::blocking_read(self, stream, len).await }).map(xform)
in_tokio(async { AsyncHostInputpStream::blocking_read(self, stream, len).await })
.map(xform)
}

fn skip(
&mut self,
stream: Resource<InputStream>,
len: u64,
) -> anyhow::Result<Result<(u64, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::skip(self, stream, len).await }).map(xform)
in_tokio(async { AsyncHostInputpStream::skip(self, stream, len).await }).map(xform)
}

fn blocking_skip(
&mut self,
stream: Resource<InputStream>,
len: u64,
) -> anyhow::Result<Result<(u64, streams::StreamStatus), ()>> {
in_tokio(async { AsyncHost::blocking_skip(self, stream, len).await }).map(xform)
in_tokio(async { AsyncHostInputpStream::blocking_skip(self, stream, len).await })
.map(xform)
}

fn subscribe(
&mut self,
stream: Resource<InputStream>,
) -> anyhow::Result<Resource<Pollable>> {
AsyncHost::subscribe_to_input_stream(self, stream)
AsyncHostInputStream::subscribe(self, stream)
}
}
}
4 changes: 2 additions & 2 deletions crates/wasi/src/preview2/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<T: WasiView> crate::preview2::bindings::io::poll::HostPollable for T {

pub mod sync {
use crate::preview2::{
bindings::io::poll::Host as AsyncHost,
bindings::io::poll::HostPollable as AsyncHostPollable,
bindings::sync_io::io::poll::{self, Pollable},
in_tokio, WasiView,
};
Expand All @@ -218,7 +218,7 @@ pub mod sync {

impl<T: WasiView> crate::preview2::bindings::sync_io::io::poll::HostPollable for T {
fn drop(&mut self, pollable: Resource<Pollable>) -> Result<()> {
AsyncHost::drop(self, pollable)
AsyncHostPollable::drop(self, pollable)
}
}
}
2 changes: 1 addition & 1 deletion crates/wasi/src/preview2/preview1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ impl<
for (entry, d_next) in self
.table_mut()
// remove iterator from table and use it directly:
.delete_readdir(stream)?
.delete_readdir(stream.rep())?
.into_iter()
.zip(3u64..)
{
Expand Down

0 comments on commit e6f651e

Please sign in to comment.