static const int DEFAULT_LAZY_POLLING_TOTAL_MS = 0;
static const int DEFAULT_LAZY_POLLING_SLEEP_MS = 1000;
-static const int MS_TO_US = 1000;
+static const int S_TO_MS = 1000;
+static const int MS_TO_NS = 1000000;
/**
* @brief Parse permissions
return 0;
}
+int sleep_while_handling_socket(struct logger *server, struct epoll_metadata *metadata, int timeout)
+{
+ struct timespec now;
+
+ do {
+ int r = handle_epoll_events(server, metadata, timeout);
+ if (r < 0)
+ return r;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ timeout -= (now.tv_sec - server->now.tv_sec) * S_TO_MS + (now.tv_nsec - server->now.tv_nsec) / MS_TO_NS;
+ server->now.tv_sec = now.tv_sec;
+ server->now.tv_nsec = now.tv_nsec;
+ } while (timeout > 0);
+
+ return 0;
+}
+
/**
* @brief Do logging
* @details The main logging loop
use_lazy_polling = (server->lazy_polling_total >= 0);
}
if (use_lazy_polling)
- usleep(MS_TO_US * server->lazy_polling_sleep);
+ sleep_while_handling_socket(server, &server->epoll_socket, server->lazy_polling_sleep);
int r = handle_epoll_events(server, &server->epoll_common, server->epolltime * !use_lazy_polling);
if (r < 0)