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

looper: Provide event value to file descriptor poll callback #435

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

MarijnS95
Copy link
Member

@MarijnS95 MarijnS95 commented Oct 7, 2023

When looper calls a callback that triggered for a poll on a file descriptor it provides the reason for the wakeup, because users are allowed to register multiple. Hence it is important for the user to know the trigger reason to enact on the result appropriately. E.g. a HANGUP typically requires the callback to be deregistered by returning false, as the other end (for a pipe() or socket()) has been closed and this file descriptor should no longer trigger any other event.

Note that various events are received by this callback regardless of whether the user registered it with that flag in events. This is all reflected by updating the documentation comments for FdEvent based on upstream Android documentation.

Keep in mind that FdEvent is a bitflag, and Android uses that to batch up multiple events. E.g. writing to a pipe() and closing the write fd - while the read fd is registered in a callback - causes the callback (from a subsequent looper.poll*()) to be called with INPUT | HANGUP, indicating that there is data to read but that the file descriptor will be dormant after that.

@MarijnS95 MarijnS95 added the impact: breaking API/ABI-breaking change label Oct 7, 2023
When `looper` calls a callback that triggered for a poll on a file
descriptor it provides the reason for the wakeup, because users are
allowed to register multiple.  Hence it is important for the user to
know the trigger reason to enact on the result appropriately.  E.g. a
`HANGUP` typically requires the callback to be deregistered by returning
`false`, as the other end (for a `pipe()` or `socket()`) has been closed
and this file descriptor should no longer trigger any other event.

Note that various events are received by this callback regardless of
whether the user registered it with that flag in `events`. This is all
reflected by updating the documentation comments for `FdEvent` based
on upstream Android documentation.

Keep in mind that `FdEvent` is a `bitflag`, and Android uses that to
batch up multiple events.  E.g. writing to a `pipe()` and closing the
write `fd` - while the read `fd` is registered in a callback - causes
the callback (from a subsequent `looper.poll*()`) to be called with
`INPUT | HANGUP`, indicating that there is data to read but that the
file descriptor will be dormant after that.
@MarijnS95 MarijnS95 force-pushed the looper-fd-callback-event-value branch from ff8a91e to 6903a9f Compare October 10, 2023 09:16
@MarijnS95 MarijnS95 merged commit 3b124fa into master Oct 10, 2023
@MarijnS95 MarijnS95 deleted the looper-fd-callback-event-value branch October 10, 2023 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact: breaking API/ABI-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant