fix(wasi): enable all WasiFiles to be pollable (#3913)
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>
This commit is contained in:
committed by
GitHub
parent
13b9396931
commit
0df4e961c0
@@ -31,6 +31,15 @@ impl WasiFile for Stdin {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
#[cfg(unix)]
|
||||
fn pollable(&self) -> Option<rustix::fd::BorrowedFd> {
|
||||
Some(self.0.as_fd())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn pollable(&self) -> Option<io_extras::os::windows::RawHandleOrSocket> {
|
||||
Some(self.0.as_raw_handle_or_socket())
|
||||
}
|
||||
async fn get_filetype(&mut self) -> Result<FileType, Error> {
|
||||
if self.isatty() {
|
||||
Ok(FileType::CharacterDevice)
|
||||
@@ -98,6 +107,15 @@ macro_rules! wasi_file_write_impl {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
#[cfg(unix)]
|
||||
fn pollable(&self) -> Option<rustix::fd::BorrowedFd> {
|
||||
Some(self.0.as_fd())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn pollable(&self) -> Option<io_extras::os::windows::RawHandleOrSocket> {
|
||||
Some(self.0.as_raw_handle_or_socket())
|
||||
}
|
||||
async fn get_filetype(&mut self) -> Result<FileType, Error> {
|
||||
if self.isatty() {
|
||||
Ok(FileType::CharacterDevice)
|
||||
|
||||
Reference in New Issue
Block a user