7 #include "eventloopinterface.h" 18 constexpr uint64_t USEC_INFINITY =
static_cast<uint64_t
>(-1);
19 constexpr uint64_t USEC_PER_SEC = 1000000ULL;
20 constexpr uint64_t NSEC_PER_USEC = 1000ULL;
22 std::string getErrorMessage(
int error) {
26 return std::format(
"EventLoopException: {0}", std::strerror(error));
32 uint64_t timespec_load(
const struct timespec *ts) {
33 if (ts->tv_sec == (time_t)-1 && ts->tv_nsec == (
long)-1) {
37 if ((uint64_t)ts->tv_sec >
38 (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC) {
42 return (uint64_t)ts->tv_sec * USEC_PER_SEC +
43 (uint64_t)ts->tv_nsec / NSEC_PER_USEC;
46 uint64_t now(clockid_t clock_id) {
48 clock_gettime(clock_id, &ts);
50 return timespec_load(&ts);
53 EventLoopException::EventLoopException(
int error)
54 :
std::runtime_error(getErrorMessage(error)), errno_(error) {}
56 void EventSourceTime::setNextInterval(uint64_t time) {
57 setTime(now(clock()) + time);
60 EventSource::~EventSource() =
default;
62 EventLoopInterface::~EventLoopInterface() =
default;