Currently, the use of the downcast method means that you have to use one of the hard-coded types. But Enarx needs to define its own `WasiFile` implementations. This works fine, except the resulting files cannot be used in poll because they aren't part of the hard-coded list. Replace this with an accessor method for the pollable type in `WasiFile`. Because we provide a default implementation of the method and manually implement it on all the hard-coded types, this is backwards compatible. Signed-off-by: Nathaniel McCallum <nathaniel@profian.com>
16 lines
664 B
Rust
16 lines
664 B
Rust
use crate::block_on_dummy_executor;
|
|
use wasi_cap_std_sync::sched::windows::poll_oneoff_;
|
|
use wasi_common::{file::WasiFile, sched::Poll, Error};
|
|
|
|
pub async fn poll_oneoff<'a>(poll: &mut Poll<'a>) -> Result<(), Error> {
|
|
// Tokio doesn't provide us the AsyncFd primitive on Windows, so instead
|
|
// 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
|
|
// to a RawHandle.
|
|
block_on_dummy_executor(move || poll_oneoff_(poll, wasi_file_is_stdin))
|
|
}
|
|
|
|
pub fn wasi_file_is_stdin(f: &dyn WasiFile) -> bool {
|
|
f.as_any().is::<crate::stdio::Stdin>()
|
|
}
|