You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
0 commit comments