Use zircon's status-to-error conversion
Change-Id: Ie7e4c6db4804cc65d6430e88a7b13f9c02e7eb42
diff --git a/src/sys/fuchsia/awakener.rs b/src/sys/fuchsia/awakener.rs
index a7e51ff..19bc762 100644
--- a/src/sys/fuchsia/awakener.rs
+++ b/src/sys/fuchsia/awakener.rs
@@ -1,5 +1,4 @@
use {io, poll, Evented, Ready, Poll, PollOpt, Token};
-use sys::fuchsia::status_to_io_err;
use zircon;
use std::sync::{Arc, Mutex, Weak};
@@ -30,7 +29,7 @@
let packet = zircon::Packet::from_user_packet(
token.0 as u64, status, zircon::UserPacket::from_u8_array([0; 32]));
- port.queue(&packet).map_err(status_to_io_err)
+ Ok(port.queue(&packet)?)
}
pub fn cleanup(&self) {}
diff --git a/src/sys/fuchsia/mod.rs b/src/sys/fuchsia/mod.rs
index adc0cc5..10728fc 100644
--- a/src/sys/fuchsia/mod.rs
+++ b/src/sys/fuchsia/mod.rs
@@ -82,57 +82,6 @@
}
}
-/// Convert from zircon::Status to io::Error.
-///
-/// Note: these conversions are done on a "best-effort" basis and may not necessarily reflect
-/// exactly equivalent error types.
-fn status_to_io_err(status: zircon::Status) -> io::Error {
- use zircon::Status;
-
- let err_kind: io::ErrorKind = match status {
- Status::ErrInterruptedRetry => io::ErrorKind::Interrupted,
- Status::ErrBadHandle => io::ErrorKind::BrokenPipe,
- Status::ErrTimedOut => io::ErrorKind::TimedOut,
- Status::ErrShouldWait => io::ErrorKind::WouldBlock,
- Status::ErrPeerClosed => io::ErrorKind::ConnectionAborted,
- Status::ErrNotFound => io::ErrorKind::NotFound,
- Status::ErrAlreadyExists => io::ErrorKind::AlreadyExists,
- Status::ErrAlreadyBound => io::ErrorKind::AddrInUse,
- Status::ErrUnavailable => io::ErrorKind::AddrNotAvailable,
- Status::ErrAccessDenied => io::ErrorKind::PermissionDenied,
- Status::ErrIoRefused => io::ErrorKind::ConnectionRefused,
- Status::ErrIoDataIntegrity => io::ErrorKind::InvalidData,
-
- Status::ErrBadPath |
- Status::ErrInvalidArgs |
- Status::ErrOutOfRange |
- Status::ErrWrongType => io::ErrorKind::InvalidInput,
-
- Status::UnknownOther |
- Status::ErrNext |
- Status::ErrStop |
- Status::ErrNoSpace |
- Status::ErrFileBig |
- Status::ErrNotFile |
- Status::ErrNotDir |
- Status::ErrIoDataLoss |
- Status::ErrIo |
- Status::ErrCanceled |
- Status::ErrBadState |
- Status::ErrBufferTooSmall |
- Status::ErrBadSyscall |
- Status::NoError |
- Status::ErrInternal |
- Status::ErrNotSupported |
- Status::ErrNoResources |
- Status::ErrNoMemory |
- Status::ErrCallFailed
- => io::ErrorKind::Other
- }.into();
-
- err_kind.into()
-}
-
fn epoll_event_to_ready(epoll: u32) -> Ready {
let epoll = epoll as i32; // casts the bits directly
let mut kind = Ready::empty();
diff --git a/src/sys/fuchsia/selector.rs b/src/sys/fuchsia/selector.rs
index 86c465e..643a7b8 100644
--- a/src/sys/fuchsia/selector.rs
+++ b/src/sys/fuchsia/selector.rs
@@ -3,7 +3,6 @@
assert_fuchsia_ready_repr,
epoll_event_to_ready,
poll_opts_to_wait_async,
- status_to_io_err,
EventedFd,
EventedFdInner,
FuchsiaReady,
@@ -96,8 +95,7 @@
assert_fuchsia_ready_repr();
let port = Arc::new(
- zircon::Port::create(zircon::PortOpts::Default)
- .map_err(status_to_io_err)?
+ zircon::Port::create(zircon::PortOpts::Default)?
);
// offset by 1 to avoid choosing 0 as the id of a selector
@@ -164,7 +162,7 @@
let packet = match self.port.wait(deadline) {
Ok(packet) => packet,
Err(zircon::Status::ErrTimedOut) => return Ok(false),
- Err(e) => return Err(status_to_io_err(e)),
+ Err(e) => Err(e)?,
};
let observed_signals = match packet.contents() {
@@ -256,14 +254,13 @@
let wait_async_opts = poll_opts_to_wait_async(poll_opts);
- let wait_res = handle.wait_async_handle(&self.port, token.0 as u64, signals, wait_async_opts)
- .map_err(status_to_io_err);
+ let wait_res = handle.wait_async_handle(&self.port, token.0 as u64, signals, wait_async_opts);
if wait_res.is_err() {
self.token_to_fd.lock().unwrap().remove(&token);
}
- wait_res
+ Ok(wait_res?)
}
/// Deregister event interests for the given IO handle with the OS
@@ -273,7 +270,7 @@
// We ignore NotFound errors since oneshots are automatically deregistered,
// but mio will attempt to deregister them manually.
self.port.cancel(&*handle, token.0 as u64)
- .map_err(status_to_io_err)
+ .map_err(io::Error::from)
.or_else(|e| if e.kind() == io::ErrorKind::NotFound {
Ok(())
} else {
@@ -298,24 +295,22 @@
&self.port,
key_from_token_and_type(token, RegType::Handle)?,
FuchsiaReady::from(interests).into_zx_signals(),
- poll_opts_to_wait_async(poll_opts))
- .map_err(status_to_io_err);
+ poll_opts_to_wait_async(poll_opts));
mem::forget(temp_handle);
- res
+ Ok(res?)
}
pub fn deregister_handle(&self, handle: zx_handle_t, token: Token) -> io::Result<()>
{
let temp_handle = unsafe { zircon::Handle::from_raw(handle) };
- let res = self.port.cancel(&temp_handle, key_from_token_and_type(token, RegType::Handle)?)
- .map_err(status_to_io_err);
+ let res = self.port.cancel(&temp_handle, key_from_token_and_type(token, RegType::Handle)?);
mem::forget(temp_handle);
- res
+ Ok(res?)
}
}