pub struct FdSet<'fd> { /* private fields */ }
Expand description
Contains a set of file descriptors used by select
Implementations§
source§impl<'fd> FdSet<'fd>
impl<'fd> FdSet<'fd>
sourcepub fn insert(&mut self, fd: BorrowedFd<'fd>)
pub fn insert(&mut self, fd: BorrowedFd<'fd>)
Add a file descriptor to an FdSet
sourcepub fn remove(&mut self, fd: BorrowedFd<'fd>)
pub fn remove(&mut self, fd: BorrowedFd<'fd>)
Remove a file descriptor from an FdSet
sourcepub fn contains(&self, fd: BorrowedFd<'fd>) -> bool
pub fn contains(&self, fd: BorrowedFd<'fd>) -> bool
Test an FdSet
for the presence of a certain file descriptor.
sourcepub fn highest(&self) -> Option<BorrowedFd<'_>>
pub fn highest(&self) -> Option<BorrowedFd<'_>>
Finds the highest file descriptor in the set.
Returns None
if the set is empty.
This can be used to calculate the nfds
parameter of the select
function.
§Example
let fd_four = unsafe {BorrowedFd::borrow_raw(4)};
let fd_nine = unsafe {BorrowedFd::borrow_raw(9)};
let mut set = FdSet::new();
set.insert(fd_four);
set.insert(fd_nine);
assert_eq!(set.highest().map(|borrowed_fd|borrowed_fd.as_raw_fd()), Some(9));
sourcepub fn fds(&self, highest: Option<RawFd>) -> Fds<'_, '_> ⓘ
pub fn fds(&self, highest: Option<RawFd>) -> Fds<'_, '_> ⓘ
Returns an iterator over the file descriptors in the set.
For performance, it takes an optional higher bound: the iterator will not return any elements of the set greater than the given file descriptor.
§Examples
let mut set = FdSet::new();
let fd_four = unsafe {BorrowedFd::borrow_raw(4)};
let fd_nine = unsafe {BorrowedFd::borrow_raw(9)};
set.insert(fd_four);
set.insert(fd_nine);
let fds: Vec<RawFd> = set.fds(None).map(|borrowed_fd|borrowed_fd.as_raw_fd()).collect();
assert_eq!(fds, vec![4, 9]);
Trait Implementations§
impl<'fd> Copy for FdSet<'fd>
impl<'fd> Eq for FdSet<'fd>
impl<'fd> StructuralPartialEq for FdSet<'fd>
Auto Trait Implementations§
impl<'fd> Freeze for FdSet<'fd>
impl<'fd> RefUnwindSafe for FdSet<'fd>
impl<'fd> Send for FdSet<'fd>
impl<'fd> Sync for FdSet<'fd>
impl<'fd> Unpin for FdSet<'fd>
impl<'fd> UnwindSafe for FdSet<'fd>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)