@@ -32,9 +32,8 @@ impl FdSet {
32
32
unsafe { libc:: FD_CLR ( fd, & mut self . 0 ) } ;
33
33
}
34
34
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 ) }
38
37
}
39
38
40
39
pub fn clear ( & mut self ) {
@@ -61,11 +60,13 @@ impl FdSet {
61
60
/// ```
62
61
///
63
62
/// [`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 ( )
66
65
}
67
66
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.
69
70
///
70
71
/// # Examples
71
72
///
@@ -76,14 +77,14 @@ impl FdSet {
76
77
/// let mut set = FdSet::new();
77
78
/// set.insert(4);
78
79
/// set.insert(9);
79
- /// let fds: Vec<RawFd> = set.fds().collect();
80
+ /// let fds: Vec<RawFd> = set.fds(None ).collect();
80
81
/// assert_eq!(fds, vec![4, 9]);
81
82
/// ```
82
83
#[ inline]
83
- pub fn fds ( & self ) -> Fds {
84
+ pub fn fds ( & mut self , highest : Option < RawFd > ) -> Fds {
84
85
Fds {
85
86
set : self ,
86
- range : 0 ..FD_SETSIZE ,
87
+ range : 0 ..highest . map ( |h| h as usize + 1 ) . unwrap_or ( FD_SETSIZE ) ,
87
88
}
88
89
}
89
90
}
@@ -95,9 +96,9 @@ impl Default for FdSet {
95
96
}
96
97
97
98
/// Iterator over `FdSet`.
98
- #[ derive( Clone , Debug ) ]
99
+ #[ derive( Debug ) ]
99
100
pub struct Fds < ' a > {
100
- set : & ' a FdSet ,
101
+ set : & ' a mut FdSet ,
101
102
range : Range < usize > ,
102
103
}
103
104
0 commit comments