#include <system_info.h>
#define UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS 100
+#define UDEV_MONITOR_POLL_ITERATIONS 10 //! How many times to poll? Affects the total timeout.
int peripheral_lock(const char *file_name)
{
pfd.fd = udev_monitor_get_fd(monitor);
pfd.events = POLLIN;
- for (int cnt = 0; cnt < 10; cnt++) {
- _D("poll iteration");
- if (poll(&pfd, 1, UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS) < 0) {
- _E("Failed to watch udev monitor");
+ for (int cnt = 0; cnt < UDEV_MONITOR_POLL_ITERATIONS; cnt++) {
+ _D("poll iteration %d", cnt);
+ int ready = poll(&pfd, 1, UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS);
+ if (ready < 0) {
+ _E("Failed to watch udev monitor %m");
return -EIO;
}
+ if (ready == 0)
+ continue;
+
struct udev_device *dev = udev_monitor_receive_device(monitor);
if (dev) {
if (func(dev, func_data)) {