windows fixes

This commit is contained in:
Pat Hickey
2021-05-07 15:51:33 -07:00
parent 86bd56f6d1
commit 548b6c5311
2 changed files with 14 additions and 4 deletions

View File

@@ -25,12 +25,13 @@ use wasi_common::{
}; };
pub async fn poll_oneoff<'a>(poll: &mut Poll<'a>) -> Result<(), Error> { pub async fn poll_oneoff<'a>(poll: &mut Poll<'a>) -> Result<(), Error> {
poll_oneoff_(poll, wasi_file_raw_handle).await poll_oneoff_(poll, wasi_file_is_stdin, wasi_file_raw_handle).await
} }
// For reuse by wasi-tokio, which has a different WasiFile -> RawHandle translator. // For reuse by wasi-tokio, which has a different WasiFile -> RawHandle translator.
pub async fn poll_oneoff_<'a>( pub async fn poll_oneoff_<'a>(
poll: &mut Poll<'a>, poll: &mut Poll<'a>,
file_is_stdin: impl Fn(&dyn WasiFile) -> bool,
file_to_handle: impl Fn(&dyn WasiFile) -> Option<RawHandle>, file_to_handle: impl Fn(&dyn WasiFile) -> Option<RawHandle>,
) -> Result<(), Error> { ) -> Result<(), Error> {
if poll.is_empty() { if poll.is_empty() {
@@ -58,7 +59,7 @@ pub async fn poll_oneoff_<'a>(
for s in poll.rw_subscriptions() { for s in poll.rw_subscriptions() {
match s { match s {
Subscription::Read(r) => { Subscription::Read(r) => {
if r.file.as_any().is::<crate::stdio::Stdin>() { if file_is_stdin(r.file.deref()) {
stdin_read_subs.push(r); stdin_read_subs.push(r);
} else if file_to_handle(r.file.deref()).is_some() { } else if file_to_handle(r.file.deref()).is_some() {
immediate_reads.push(r); immediate_reads.push(r);
@@ -69,7 +70,7 @@ pub async fn poll_oneoff_<'a>(
} }
} }
Subscription::Write(w) => { Subscription::Write(w) => {
if wasi_file_raw_handle(w.file.deref()).is_some() { if file_to_handle(w.file.deref()).is_some() {
immediate_writes.push(w); immediate_writes.push(w);
} else { } else {
return Err( return Err(
@@ -133,6 +134,11 @@ pub async fn poll_oneoff_<'a>(
Ok(()) Ok(())
} }
pub fn wasi_file_is_stdin(f: &dyn WasiFile) -> bool {
f.as_any().is::<crate::stdio::Stdin>()
}
pub fn wasi_file_raw_handle(f: &dyn WasiFile) -> Option<RawHandle> { pub fn wasi_file_raw_handle(f: &dyn WasiFile) -> Option<RawHandle> {
let a = f.as_any(); let a = f.as_any();
if a.is::<crate::file::File>() { if a.is::<crate::file::File>() {

View File

@@ -8,7 +8,11 @@ pub async fn poll_oneoff<'a>(poll: &mut Poll<'a>) -> Result<(), Error> {
// we use the blocking poll_oneoff implementation from the wasi-cap-std-crate. // we use the blocking poll_oneoff implementation from the wasi-cap-std-crate.
// We provide a function specific to this crate's WasiFile types for downcasting // We provide a function specific to this crate's WasiFile types for downcasting
// to a RawHandle. // to a RawHandle.
block_on_dummy_executor(move || poll_oneoff_(poll, wasi_file_raw_handle)) block_on_dummy_executor(move || poll_oneoff_(poll, wasi_file_is_stdin, wasi_file_raw_handle))
}
pub fn wasi_file_is_stdin(f: &dyn WasiFile) -> bool {
f.as_any().is::<crate::stdio::Stdin>()
} }
fn wasi_file_raw_handle(f: &dyn WasiFile) -> Option<RawHandle> { fn wasi_file_raw_handle(f: &dyn WasiFile) -> Option<RawHandle> {