use anyhow::Context;
use fehler::{throw, throws};
use libc::_exit;
- use nix::errno::Errno::*;
use nix::{unistd::*, fcntl::OFlag};
use nix::sys::signal::*;
- use nix::Error::Sys;
+ use nix::Error as NE;
use void::Void;
use std::io;
use std::os::unix::io::RawFd;
match nix::unistd::read(fd, &mut buf) {
Ok(0) => break,
Ok(_) => throw!(io::Error::from_raw_os_error(libc::EINVAL)),
- Err(Sys(EINTR)) => continue,
+ Err(NE::EINTR) => continue,
_ => throw!(io::Error::last_os_error()),
}
}
for fd in 2.. {
if fd == notify_writing_end { continue }
let r = close(fd);
- if fd > writing_end && matches!(r, Err(Sys(EBADF))) {
+ if fd > writing_end && matches!(r, Err(NE::EBADF)) {
break;
}
}
pub trait TimedRead : Timed + Read { }
pub trait TimedWrite: Timed + Write { }
-use io::ErrorKind as EK;
-
use nix::fcntl::{fcntl, OFlag, FcntlArg};
use nix::Error as NE;
-use nix::errno::Errno;
use mio::Token;
fn as_raw_fd(&self) -> RawFd { self.0 }
}
-#[ext(pub)]
-impl nix::Error {
- fn as_ioe(self) -> io::Error {
- match self {
- NE::Sys(e) => return io::Error::from_raw_os_error(e as i32),
- NE::UnsupportedOperation => EK::Unsupported,
- NE::InvalidPath => EK::InvalidData,
- NE::InvalidUtf8 => EK::InvalidData,
- }.into()
- }
-}
-
impl<RW> TimedFd<RW> where RW: TimedFdReadWrite {
/// Takes ownership of the fd
///
#[throws(io::Error)]
fn from_fd(fd: Fd) -> Self {
fcntl(fd.as_raw_fd(), FcntlArg::F_SETFL(OFlag::O_NONBLOCK))
- .map_err(|e| e.as_ioe())?;
+ .map_err(|e| io::Error::from(e))?;
let poll = mio::Poll::new()?;
poll.registry().register(
if event.token() == Token(0) {
match f(self.fd.as_raw_fd()) {
Ok(got) => { break 'again got },
- Err(NE::Sys(Errno::EINTR)) => continue 'again,
- Err(NE::Sys(Errno::EAGAIN)) => break,
- Err(ne) => throw!(ne.as_ioe()),
+ Err(NE::EINTR) => continue 'again,
+ Err(NE::EAGAIN) => break,
+ Err(ne) => throw!(ne),
}
}
}