pub struct Selector { /* private fields */ }
Expand description
Select abstraction allowing you to monitor specified sockets.
Selector itself represents set of file descriptors to monitor, as such it is possible
to copy it.
Normally select modifies list of file descriptors, but Selector
always copies existing list,
avoiding these modifications.
Performance recommendations
Generally limited to 64 file descriptors, but you should only use select when you have ~10 fds
otherwise modern API like kqueue
or epoll
would yield much better performance.
- Call select only when getting would block from syscall;
- Limit number of selects, allowing it to accumulate events;
Implementations§
source§impl Selector
impl Selector
sourcepub fn add_read<T: AsRawFd>(&mut self, source: &T)
pub fn add_read<T: AsRawFd>(&mut self, source: &T)
Adds source
to monitor for read ops.
Panics when goes over FD_LIMIT
sourcepub fn add_write<T: AsRawFd>(&mut self, source: &T)
pub fn add_write<T: AsRawFd>(&mut self, source: &T)
Adds source
to monitor for write ops.
Panics when goes over FD_LIMIT
sourcepub fn add_except<T: AsRawFd>(&mut self, source: &T)
pub fn add_except<T: AsRawFd>(&mut self, source: &T)
Adds source
to monitor for exceptional ops.
Panics when goes over FD_LIMIT
sourcepub fn clear_read(&mut self)
pub fn clear_read(&mut self)
Removes all fds from read monitoring
sourcepub fn clear_write(&mut self)
pub fn clear_write(&mut self)
Removes all fds from write monitoring
sourcepub fn clear_except(&mut self)
pub fn clear_except(&mut self)
Removes all fds from except monitoring
sourcepub fn select(&self) -> Result<SelectResult>
pub fn select(&self) -> Result<SelectResult>
Performs select, awaiting indefinitely until at least one descriptor has changes.
sourcepub fn try_select(&self) -> Result<SelectResult>
pub fn try_select(&self) -> Result<SelectResult>
Performs select, checking file descriptors for changes and returning immediately.
sourcepub fn select_timeout(&self, time: Duration) -> Result<SelectResult>
pub fn select_timeout(&self, time: Duration) -> Result<SelectResult>
Performs select, awaiting at most time
until at least one descriptor has changes.