<poll.h> Library
I learned about the <poll.h> library. The purpose of this library is to function as an event listener. The library includes a function that waits for a set of file descriptors to become ready for I/O operations (input, output). I used this library in parallel with a thread where I monitor a GPIO pin for events triggered by pressing a push-button on my Raspberry Pi board. When the push button is pressed and the voltage increases, the interrupt is triggered and will activate or deactivate an LED based on a defined function I created.
The pollfd structure is used to store information about a file descriptor.
The first argument is the file descriptor.
The second argument is the events the file descriptor is interested in.
The third argument is the events that have occurred.
The poll() function is used to wait for a set of file descriptors to become ready for I/O operations.
The first argument is a pointer to an array of pollfd structures.
The second argument is the number of elements in the array.
The third argument is the timeout in milliseconds.
The function returns the number of file descriptors ready for I/O operations, or
-1
if an error occurs.
Simple implementation of the poll library:
Here is the documentation for the poll.h library
Last updated