wasi-common error cleanup: part 1, yanix (#1226)
* Reuse std::io::Error for raw *nix errno This commit removes custom `yanix::Errno` and instead (as was previously suggested) reuses `std::io::Error` to generate and wrap raw *nix errno value. * Update wasi-common to use new Yanix error type This commit updates `wasi-common` to use new way of handling raw OS error in `yanix`; i.e., via re-use of `std::io::Error` instead of a custom `Errno` enum. * Fix formatting * Unwrap if io::Error created from raw OS error This commit calls `unwrap` on `err` if that one was created via `io::Error::last_os_error()`. It also refactors error matching in several syscalls on the BSD platform (mainly).
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#![allow(unused_unsafe)]
|
||||
use crate::hostcalls_impl::{ClockEventData, FdEventData};
|
||||
use crate::{wasi, Error, Result};
|
||||
use std::io;
|
||||
use yanix::clock::{clock_getres, clock_gettime, ClockId};
|
||||
|
||||
fn wasi_clock_id_to_unix(clock_id: wasi::__wasi_clockid_t) -> Result<ClockId> {
|
||||
@@ -54,10 +55,7 @@ pub(crate) fn poll_oneoff(
|
||||
events: &mut Vec<wasi::__wasi_event_t>,
|
||||
) -> Result<()> {
|
||||
use std::{convert::TryInto, os::unix::prelude::AsRawFd};
|
||||
use yanix::{
|
||||
poll::{poll, PollFd, PollFlags},
|
||||
Errno,
|
||||
};
|
||||
use yanix::poll::{poll, PollFd, PollFlags};
|
||||
|
||||
if fd_events.is_empty() && timeout.is_none() {
|
||||
return Ok(());
|
||||
@@ -88,10 +86,11 @@ pub(crate) fn poll_oneoff(
|
||||
let ready = loop {
|
||||
match poll(&mut poll_fds, poll_timeout) {
|
||||
Err(_) => {
|
||||
if Errno::last() == Errno::EINTR {
|
||||
let last_err = io::Error::last_os_error();
|
||||
if last_err.raw_os_error().unwrap() == libc::EINTR {
|
||||
continue;
|
||||
}
|
||||
return Err(Errno::last().into());
|
||||
return Err(last_err.into());
|
||||
}
|
||||
Ok(ready) => break ready,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user