Skip to content

Commit

Permalink
Merge pull request Smithay#38 from ids1024/as-fd
Browse files Browse the repository at this point in the history
Implement `AsFd` for `Socket`
  • Loading branch information
Drakulix committed Dec 16, 2022
2 parents 3002527 + 277af86 commit ac4b758
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -11,6 +11,7 @@ keywords = ["udev", "hardware", "bindings", "sysfs"]
readme = "README.md"

[dependencies]
io-lifetimes = "1.0.3"
libudev-sys = "0.1.4"
libc = "0.2"
mio06 = { package = "mio", version = "^0.6.21", optional = true }
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -4,6 +4,7 @@

#![warn(missing_docs)]

extern crate io_lifetimes;
extern crate libc;
pub extern crate libudev_sys as ffi;
#[cfg(feature = "mio06")]
Expand Down
9 changes: 9 additions & 0 deletions src/monitor.rs
Expand Up @@ -6,6 +6,7 @@ use std::io::Result;
use std::ops::Deref;
use std::os::unix::io::{AsRawFd, RawFd};

use io_lifetimes::{AsFd, BorrowedFd};
#[cfg(feature = "mio06")]
use mio06::{event::Evented, unix::EventedFd, Poll, PollOpt, Ready, Token};
#[cfg(feature = "mio07")]
Expand Down Expand Up @@ -161,6 +162,14 @@ impl AsRawFd for Socket {
}
}

/// Provides raw access to the monitor's socket.
impl AsFd for Socket {
/// Returns the file descriptor of the monitor's socket.
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
}
}

pub struct SocketIter {
udev: Udev,
monitor: *mut ffi::udev_monitor,
Expand Down

0 comments on commit ac4b758

Please sign in to comment.