Unix select system call in Rust Unix select system call in Rust unix unix

Unix select system call in Rust


select is a C function which modifies the arguments you pass to it (the file descriptor sets) in-place, rather than allocating and returning an entirely new structure. nix::select is just a thin wrapper for that C function. Python is really the outlier here, as it deviates from the C API by allocating entirely separate lists containing the results.

When using nix::select, you should check the FD sets you pass in - they will have been modified to contain only the ready file descriptors.

let mut readfds = FdSet::new();readfds.insert(0);readfds.insert(3);let _ = select(&mut readfds, None, None)for fd in readfds.fds(None) {    println!("{:?}", fd);}

FdSet::fds returns an iterator over the file descriptors in the set.