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

Function select

src/backend/libc/event/syscalls.rs:216–289  ·  view source on GitHub ↗
(
    nfds: i32,
    readfds: Option<&mut [FdSetElement]>,
    writefds: Option<&mut [FdSetElement]>,
    exceptfds: Option<&mut [FdSetElement]>,
    timeout: Option<&Timespec>,
)

Source from the content-addressed store, hash-verified

214
215#[cfg(any(bsd, linux_kernel))]
216pub(crate) unsafe fn select(
217 nfds: i32,
218 readfds: Option<&mut [FdSetElement]>,
219 writefds: Option<&mut [FdSetElement]>,
220 exceptfds: Option<&mut [FdSetElement]>,
221 timeout: Option<&Timespec>,
222) -> io::Result<i32> {
223 let len = crate::event::fd_set_num_elements_for_bitvector(nfds);
224
225 let readfds = match readfds {
226 Some(readfds) => {
227 assert!(readfds.len() >= len);
228 readfds.as_mut_ptr()
229 }
230 None => null_mut(),
231 };
232 let writefds = match writefds {
233 Some(writefds) => {
234 assert!(writefds.len() >= len);
235 writefds.as_mut_ptr()
236 }
237 None => null_mut(),
238 };
239 let exceptfds = match exceptfds {
240 Some(exceptfds) => {
241 assert!(exceptfds.len() >= len);
242 exceptfds.as_mut_ptr()
243 }
244 None => null_mut(),
245 };
246
247 let timeout_data;
248 let timeout_ptr = match timeout {
249 Some(timeout) => {
250 // Convert from `Timespec` to `c::timeval`.
251 timeout_data = c::timeval {
252 tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::INVAL)?,
253 tv_usec: ((timeout.tv_nsec + 999) / 1000) as _,
254 };
255 &timeout_data
256 }
257 None => null(),
258 };
259
260 // On Apple platforms, use the specially mangled `select` which doesn't
261 // have an `FD_SETSIZE` limitation.
262 #[cfg(apple)]
263 {
264 extern "C" {
265 #[link_name = "select$DARWIN_EXTSN$NOCANCEL"]
266 fn select(
267 nfds: c::c_int,
268 readfds: *mut FdSetElement,
269 writefds: *mut FdSetElement,
270 errorfds: *mut FdSetElement,
271 timeout: *const c::timeval,
272 ) -> c::c_int;
273 }

Callers

nothing calls this directly

Calls 4

ret_c_intFunction · 0.50
as_mut_ptrMethod · 0.45

Tested by

no test coverage detected