android_looper_sys::ALooper_addFd
[−]
[src]
pub unsafe extern fn ALooper_addFd(looper: *mut ALooper, fd: c_int, ident: c_int, events: c_int, callback: ALooper_callbackFunc, data: *mut c_void) -> c_int
Adds a new file descriptor to be polled by the looper. If the same file descriptor was previously added, it is replaced.
- "fd" is the file descriptor to be added.
- "ident" is an identifier for this event, which is returned from ALooper_pollOnce(). The identifier must be >= 0, or ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
- "events" are the poll events to wake up on. Typically this is ALOOPER_EVENT_INPUT.
- "callback" is the function to call when there is an event on the file descriptor.
- "data" is a private data pointer to supply to the callback.
There are two main uses of this function:
(1) If "callback" is non-NULL, then this function will be called when there is data on the file descriptor. It should execute any events it has pending, appropriately reading from the file descriptor. The 'ident' is ignored in this case.
(2) If "callback" is NULL, the 'ident' will be returned by ALooper_pollOnce when its file descriptor has data available, requiring the caller to take care of processing it.
Returns 1 if the file descriptor was added or -1 if an error occurred.
This method can be called on any thread. This method may block briefly if it needs to wake the poll.