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

Method filter

src/event/kqueue.rs:108–155  ·  view source on GitHub ↗

Get the filter of this event.

(&self)

Source from the content-addressed store, hash-verified

106
107 /// Get the filter of this event.
108 pub fn filter(&self) -> EventFilter {
109 match self.inner.filter as _ {
110 c::EVFILT_READ => EventFilter::Read(self.inner.ident as _),
111 c::EVFILT_WRITE => EventFilter::Write(self.inner.ident as _),
112 #[cfg(target_os = "freebsd")]
113 c::EVFILT_EMPTY => EventFilter::Empty(self.inner.ident as _),
114 c::EVFILT_VNODE => EventFilter::Vnode {
115 vnode: self.inner.ident as _,
116 flags: VnodeEvents::from_bits_retain(self.inner.fflags),
117 },
118 c::EVFILT_PROC => EventFilter::Proc {
119 pid: Pid::from_raw(self.inner.ident as _).unwrap(),
120 flags: ProcessEvents::from_bits_retain(self.inner.fflags),
121 },
122 c::EVFILT_SIGNAL => EventFilter::Signal {
123 // SAFETY: `EventFilter::new` requires a valid `Signal`.
124 signal: unsafe { Signal::from_raw_unchecked(self.inner.ident as _) },
125 times: self.inner.data as _,
126 },
127 c::EVFILT_TIMER => EventFilter::Timer {
128 ident: self.inner.ident as _,
129 timer: {
130 let (data, fflags) = (self.inner.data, self.inner.fflags);
131 #[cfg(not(any(apple, target_os = "freebsd", target_os = "netbsd")))]
132 let _ = fflags;
133 #[cfg(any(apple, target_os = "freebsd", target_os = "netbsd"))]
134 match fflags as _ {
135 c::NOTE_SECONDS => Some(Duration::from_secs(data as _)),
136 c::NOTE_USECONDS => Some(Duration::from_micros(data as _)),
137 c::NOTE_NSECONDS => Some(Duration::from_nanos(data as _)),
138 _ => {
139 // Unknown timer flags.
140 None
141 }
142 }
143 #[cfg(any(target_os = "dragonfly", target_os = "openbsd"))]
144 Some(Duration::from_millis(data as _))
145 },
146 },
147 #[cfg(any(apple, freebsdlike))]
148 c::EVFILT_USER => EventFilter::User {
149 ident: self.inner.ident as _,
150 flags: UserFlags::from_bits_retain(self.inner.fflags),
151 user_flags: UserDefinedFlags(self.inner.fflags & EVFILT_USER_FLAGS),
152 },
153 _ => EventFilter::Unknown,
154 }
155 }
156}
157
158/// Bottom 24 bits of a `u32`.

Callers 2

test_ops_plainFunction · 0.80
mainFunction · 0.80

Calls 1

UserDefinedFlagsClass · 0.85

Tested by 1

test_ops_plainFunction · 0.64