Skip to content

Commit 7b0cd34

Browse files
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 <[email protected]>
2 parents f38b721 + 7830042 commit 7b0cd34

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/sys/inotify.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use libc::{c_char, c_int};
3232
use std::ffi::{CStr, OsStr, OsString};
3333
use std::mem::{size_of, MaybeUninit};
3434
use std::os::unix::ffi::OsStrExt;
35-
use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
35+
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
3636
use std::ptr;
3737

3838
libc_bitflags! {
@@ -240,3 +240,9 @@ impl FromRawFd for Inotify {
240240
Inotify { fd: OwnedFd::from_raw_fd(fd) }
241241
}
242242
}
243+
244+
impl AsFd for Inotify {
245+
fn as_fd(&'_ self) -> BorrowedFd<'_> {
246+
self.fd.as_fd()
247+
}
248+
}

0 commit comments

Comments
 (0)