summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-02 13:20:33 +0000
committerGitHub <noreply@github.com>2023-04-02 13:20:33 +0000
commit7b0cd342b7425a0de0bde9a09c3ec17f046c76b4 (patch)
tree25543e1e260debfaec111868e721a039021e8000 /src
parentf38b721f27803acfb39a4f7e7a16cae18d1953c7 (diff)
parent7830042a6572bc1bb86429299ca1bc202c1a0710 (diff)
downloadnix-7b0cd342b7425a0de0bde9a09c3ec17f046c76b4.zip
Merge #1999
1999: inotify: Add AsFd to allow using with epoll (issue #1998) r=asomers a=VorpalBlade This resolves issue #1998 and allows `Inotify` to be used by `Epoll` by adding AsFd. I'm not entirely sure about the unit test. Maybe it would be possible to do a more comperhensive check by contructing inotify using `from_raw_fd` and checking that I get the same value back. However, that would basically mean duplicating `Inotify::new` and that feels a bit pointless. Another option would be to create an integration test to combine `Inotify` and `Epoll`. Fixes #1998 Co-authored-by: Arvid Norlander <VorpalBlade@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/sys/inotify.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/sys/inotify.rs b/src/sys/inotify.rs
index 2398c16e..e5fe930f 100644
--- a/src/sys/inotify.rs
+++ b/src/sys/inotify.rs
@@ -32,7 +32,7 @@ use libc::{c_char, c_int};
use std::ffi::{CStr, OsStr, OsString};
use std::mem::{size_of, MaybeUninit};
use std::os::unix::ffi::OsStrExt;
-use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
+use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
use std::ptr;
libc_bitflags! {
@@ -240,3 +240,9 @@ impl FromRawFd for Inotify {
Inotify { fd: OwnedFd::from_raw_fd(fd) }
}
}
+
+impl AsFd for Inotify {
+ fn as_fd(&'_ self) -> BorrowedFd<'_> {
+ self.fd.as_fd()
+ }
+}