rust-mobile / ndk

Rust bindings to the Android NDK
Apache License 2.0
1.11k stars 110 forks source link

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

Closed MarijnS95 closed 11 months ago

MarijnS95 commented 11 months ago

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.