Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1877: PollFd utility functions r=asomers a=JonathanWoollett-Light Adds `poll::PollFd::any()` and `poll::PollFd::all()` functions which returns if any/all of the events of interest occurred in the last call to `poll` or `ppoll`. Consider the case: ```rust let (first_fd, second_fd) = /* ... */; let mut poll_fds = [ poll::PollFd::new(interrupt_fd, poll::PollFlags::POLLIN), poll::PollFd::new(transfer_fd, poll::PollFlags::POLLIN), ]; let _ = poll::poll(&mut poll_fds, -1)?; let first = poll_fds[0].revents()? != poll::PollFlags::empty(); let second = poll_fds[1].revents()? != poll::PollFlags::empty();; if first { /* ... */ } if second { /* ... */ } ``` which can now be reduced: ```rust let (first_fd, second_fd) = /* ... */; let mut poll_fds = [ poll::PollFd::new(interrupt_fd, poll::PollFlags::POLLIN), poll::PollFd::new(transfer_fd, poll::PollFlags::POLLIN), ]; let _ = poll::poll(&mut poll_fds, -1)?; let first = poll_fds[0].any()?; let second = poll_fds[1].any()?; if first { /* ... */ } if second { /* ... */ } ``` Co-authored-by: Jonathan <jonathanwoollettlight@gmail.com>
- Loading branch information