| 2 | |
| 3 | #[cfg(all(bsd, feature = "event"))] |
| 4 | fn main() -> std::io::Result<()> { |
| 5 | use rustix::buffer::spare_capacity; |
| 6 | use rustix::event::kqueue::*; |
| 7 | #[cfg(feature = "fs")] |
| 8 | use rustix::{fd::AsRawFd, fs}; |
| 9 | use std::ptr::null_mut; |
| 10 | |
| 11 | let kq = kqueue()?; |
| 12 | let mut out = Vec::with_capacity(10); |
| 13 | |
| 14 | #[cfg(feature = "fs")] |
| 15 | let dir = fs::openat( |
| 16 | fs::CWD, |
| 17 | ".", |
| 18 | fs::OFlags::RDONLY | fs::OFlags::DIRECTORY | fs::OFlags::CLOEXEC, |
| 19 | fs::Mode::empty(), |
| 20 | )?; |
| 21 | |
| 22 | let subs = [ |
| 23 | #[cfg(feature = "process")] |
| 24 | Event::new( |
| 25 | EventFilter::Signal { |
| 26 | signal: rustix::process::Signal::INFO, |
| 27 | times: 0, |
| 28 | }, |
| 29 | EventFlags::ADD, |
| 30 | null_mut(), |
| 31 | ), |
| 32 | #[cfg(feature = "fs")] |
| 33 | Event::new( |
| 34 | EventFilter::Vnode { |
| 35 | vnode: dir.as_raw_fd(), |
| 36 | flags: VnodeEvents::WRITE | VnodeEvents::LINK | VnodeEvents::EXTEND, |
| 37 | }, |
| 38 | EventFlags::ADD | EventFlags::CLEAR, |
| 39 | null_mut(), |
| 40 | ), |
| 41 | Event::new( |
| 42 | EventFilter::Timer { |
| 43 | ident: 0, |
| 44 | timer: Some(std::time::Duration::from_secs(1)), |
| 45 | }, |
| 46 | EventFlags::ADD, |
| 47 | null_mut(), |
| 48 | ), |
| 49 | Event::new( |
| 50 | EventFilter::Timer { |
| 51 | ident: 1, |
| 52 | timer: Some(std::time::Duration::from_secs(2)), |
| 53 | }, |
| 54 | EventFlags::ADD | EventFlags::ONESHOT, |
| 55 | null_mut(), |
| 56 | ), |
| 57 | ]; |
| 58 | |
| 59 | eprintln!("Listening for various events"); |
| 60 | #[cfg(not(feature = "process"))] |
| 61 | eprintln!("Run with --features process to enable more!"); |