Skip to content

Commit 8b4a433

Browse files
committed
Operate on &mut
1 parent 41db1bf commit 8b4a433

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/sys/select.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ impl FdSet {
3232
unsafe { libc::FD_CLR(fd, &mut self.0) };
3333
}
3434

35-
pub fn contains(&self, fd: RawFd) -> bool {
36-
let mut copy = self.0;
37-
unsafe { libc::FD_ISSET(fd, &mut copy) }
35+
pub fn contains(&mut self, fd: RawFd) -> bool {
36+
unsafe { libc::FD_ISSET(fd, &mut self.0) }
3837
}
3938

4039
pub fn clear(&mut self) {
@@ -61,11 +60,13 @@ impl FdSet {
6160
/// ```
6261
///
6362
/// [`select`]: fn.select.html
64-
pub fn highest(&self) -> Option<RawFd> {
65-
self.fds().next_back()
63+
pub fn highest(&mut self) -> Option<RawFd> {
64+
self.fds(None).next_back()
6665
}
6766

68-
/// Returns an iterator over the file descriptors in the set.
67+
/// Returns an iterator over the file descriptors in the set. For
68+
/// performance, it takes an optional higher bound: the iterator will not
69+
/// return any elements of the set greater than the given file descriptor.
6970
///
7071
/// # Examples
7172
///
@@ -76,14 +77,14 @@ impl FdSet {
7677
/// let mut set = FdSet::new();
7778
/// set.insert(4);
7879
/// set.insert(9);
79-
/// let fds: Vec<RawFd> = set.fds().collect();
80+
/// let fds: Vec<RawFd> = set.fds(None).collect();
8081
/// assert_eq!(fds, vec![4, 9]);
8182
/// ```
8283
#[inline]
83-
pub fn fds(&self) -> Fds {
84+
pub fn fds(&mut self, highest: Option<RawFd>) -> Fds {
8485
Fds {
8586
set: self,
86-
range: 0..FD_SETSIZE,
87+
range: 0..highest.map(|h| h as usize + 1).unwrap_or(FD_SETSIZE),
8788
}
8889
}
8990
}
@@ -95,9 +96,9 @@ impl Default for FdSet {
9596
}
9697

9798
/// Iterator over `FdSet`.
98-
#[derive(Clone, Debug)]
99+
#[derive(Debug)]
99100
pub struct Fds<'a> {
100-
set: &'a FdSet,
101+
set: &'a mut FdSet,
101102
range: Range<usize>,
102103
}
103104

0 commit comments

Comments
 (0)