MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / main

Function main

examples/kq.rs:4–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3#[cfg(all(bsd, feature = "event"))]
4fn 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!");

Callers

nothing calls this directly

Calls 6

spare_capacityFunction · 0.85
filterMethod · 0.80
kqueueFunction · 0.50
openatFunction · 0.50
keventFunction · 0.50
as_raw_fdMethod · 0.45

Tested by

no test coverage detected