Skip to content

Commit 7899089

Browse files
committed
Update nix to 0.10.0
The old version was getting a bit... old. Update the dep version and deal with the small amount of fallout due to various improvements to nix upstream. Signed-off-by: Paul Osborne <[email protected]>
1 parent d44fa0b commit 7899089

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ tokio = ["futures", "tokio-core", "mio-evented"]
2121

2222
[dependencies]
2323
futures = { version = "0.1", optional = true }
24-
nix = "0.6.0"
24+
nix = "0.10.0"
2525
mio = { version = "0.6", optional = true }
2626
tokio-core = { version = "0.1", optional = true }

src/error.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::convert;
22
use std::fmt;
33
use std::io;
4+
use nix;
45

56
#[derive(Debug)]
67
pub enum Error {
@@ -50,8 +51,11 @@ impl convert::From<io::Error> for Error {
5051
}
5152
}
5253

53-
impl convert::From<::nix::Error> for Error {
54-
fn from(e: ::nix::Error) -> Error {
55-
Error::Io(io::Error::from_raw_os_error(e.errno() as i32))
54+
impl convert::From<nix::Error> for Error {
55+
fn from(e: nix::Error) -> Error {
56+
match e {
57+
nix::Error::Sys(errno) => Error::Io(errno.into()),
58+
other => Error::Unexpected(format!("{:?}", other)), // should just be dealing with errno case
59+
}
5660
}
5761
}

src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,9 @@ impl PinPoller {
515515
let devfile: File = File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num))?;
516516
let devfile_fd = devfile.as_raw_fd();
517517
let epoll_fd = epoll_create()?;
518-
let events = EPOLLPRI | EPOLLET;
519-
let info = EpollEvent {
520-
events: events,
521-
data: 0u64,
522-
};
518+
let mut event = EpollEvent::new(EpollFlags::EPOLLPRI | EpollFlags::EPOLLET, 0u64);
523519

524-
match epoll_ctl(epoll_fd, EpollOp::EpollCtlAdd, devfile_fd, &info) {
520+
match epoll_ctl(epoll_fd, EpollOp::EpollCtlAdd, devfile_fd, &mut event) {
525521
Ok(_) => {
526522
Ok(PinPoller {
527523
pin_num: pin_num,
@@ -561,10 +557,7 @@ impl PinPoller {
561557
#[cfg(any(target_os = "linux", target_os = "android"))]
562558
pub fn poll(&mut self, timeout_ms: isize) -> Result<Option<u8>> {
563559
flush_input_from_file(&mut self.devfile, 255)?;
564-
let dummy_event = EpollEvent {
565-
events: EPOLLPRI | EPOLLET,
566-
data: 0u64,
567-
};
560+
let dummy_event = EpollEvent::new(EpollFlags::EPOLLPRI | EpollFlags::EPOLLET, 0u64);
568561
let mut events: [EpollEvent; 1] = [dummy_event];
569562
let cnt = epoll_wait(self.epoll_fd, &mut events, timeout_ms)?;
570563
Ok(match cnt {

0 commit comments

Comments
 (0)