Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PollFd utility functions #1877

Merged
merged 1 commit into from Nov 29, 2022

Conversation

JonathanWoollett-Light
Copy link
Contributor

@JonathanWoollett-Light JonathanWoollett-Light commented Nov 21, 2022

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:

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:

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 { /* ... */ }

@JonathanWoollett-Light JonathanWoollett-Light force-pushed the pollfd-util-functions branch 3 times, most recently from f1df78e to 18ad17a Compare November 21, 2022 01:59
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 29, 2022

Merge conflict.

@asomers
Copy link
Member

asomers commented Nov 29, 2022

bors retry

bors bot added a commit that referenced this pull request Nov 29, 2022
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>
@bors
Copy link
Contributor

bors bot commented Nov 29, 2022

Build failed:

@asomers
Copy link
Member

asomers commented Nov 29, 2022

That looks like a spurious failure.

bors retry

@bors bors bot merged commit 2866bde into nix-rust:master Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants