Skip to content

Commit

Permalink
Support mio 0.7 as well as 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Jan 25, 2021
1 parent f8483af commit 363f692
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ readme = "README.md"
[dependencies]
libudev-sys = "0.1.4"
libc = "0.2"
mio = { version = "0.6", optional = true }
mio06 = { package = "mio", version = "0.6", optional = true }
mio07 = { package = "mio", version = "0.7", features = ["os-ext"], optional = true }

[features]
mio = ["mio07"] # mio feature defaults to the newest mio version
hwdb = []
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

extern crate libc;
pub extern crate libudev_sys as ffi;
#[cfg(feature = "mio")]
extern crate mio;
#[cfg(feature = "mio06")]
extern crate mio06;
#[cfg(feature = "mio07")]
extern crate mio07;

pub use device::{Attributes, Device, Properties};
pub use enumerator::{Devices, Enumerator};
Expand Down
37 changes: 32 additions & 5 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use std::io::Result;
use std::ops::Deref;
use std::os::unix::io::{AsRawFd, RawFd};

#[cfg(feature = "mio")]
use mio::{event::Evented, unix::EventedFd, Poll, PollOpt, Ready, Token};
#[cfg(feature = "mio06")]
use mio06::{event::Evented, unix::EventedFd, Poll, PollOpt, Ready, Token as Token06};
#[cfg(feature = "mio07")]
use mio07::{event::Source, unix::SourceFd, Registry, Token as Token07, Interest};

use Udev;
use {ffi, util};
Expand Down Expand Up @@ -250,12 +252,12 @@ impl Event {
}
}

#[cfg(feature = "mio")]
#[cfg(feature = "mio06")]
impl Evented for Socket {
fn register(
&self,
poll: &Poll,
token: Token,
token: Token06,
interest: Ready,
opts: PollOpt,
) -> std::io::Result<()> {
Expand All @@ -265,7 +267,7 @@ impl Evented for Socket {
fn reregister(
&self,
poll: &Poll,
token: Token,
token: Token06,
interest: Ready,
opts: PollOpt,
) -> std::io::Result<()> {
Expand All @@ -276,3 +278,28 @@ impl Evented for Socket {
EventedFd(&self.as_raw_fd()).deregister(poll)
}
}

#[cfg(feature = "mio07")]
impl Source for Socket {
fn register(
&mut self,
registry: &Registry,
token: Token07,
interest: Interest,
) -> std::io::Result<()> {
SourceFd(&self.as_raw_fd()).register(registry, token, interest)
}

fn reregister(
&mut self,
registry: &Registry,
token: Token07,
interest: Interest
) -> std::io::Result<()> {
SourceFd(&self.as_raw_fd()).reregister(registry, token, interest)
}

fn deregister(&mut self, registry: &Registry) -> std::io::Result<()> {
SourceFd(&self.as_raw_fd()).deregister(registry)
}
}

0 comments on commit 363f692

Please sign in to comment.