Commit 7a6823dc authored by Max Kellermann's avatar Max Kellermann

zeroconf/AvahiPoll: the struct timeval is an absolute time point

Fixes broken libavahi-client timeouts.
parent bce144a2
...@@ -105,8 +105,28 @@ public: ...@@ -105,8 +105,28 @@ public:
} }
private: private:
[[gnu::pure]]
Event::Duration AbsoluteToDuration(const struct timeval &tv) noexcept {
if (tv.tv_sec == 0)
/* schedule immediately */
return {};
struct timeval now;
if (gettimeofday(&now, nullptr) < 0)
/* shouldn't ever fail, but if it does, do
something reasonable */
return std::chrono::seconds(1);
auto d = ToSteadyClockDuration(tv)
- ToSteadyClockDuration(now);
if (d.count() < 0)
return {};
return d;
}
void Schedule(const struct timeval &tv) noexcept { void Schedule(const struct timeval &tv) noexcept {
event.Schedule(ToSteadyClockDuration(tv)); event.Schedule(AbsoluteToDuration(tv));
} }
void OnTimeout() noexcept { void OnTimeout() noexcept {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment