Commit ae35df11 authored by Max Kellermann's avatar Max Kellermann

zeroconf/AvahiPoll: move TimevalToChrono() to time/Convert.cxx

parent 80e55f6b
...@@ -81,3 +81,10 @@ MakeTime(struct tm &tm) noexcept ...@@ -81,3 +81,10 @@ MakeTime(struct tm &tm) noexcept
{ {
return std::chrono::system_clock::from_time_t(mktime(&tm)); return std::chrono::system_clock::from_time_t(mktime(&tm));
} }
std::chrono::steady_clock::duration
ToSteadyClockDuration(const struct timeval &tv) noexcept
{
return std::chrono::steady_clock::duration(std::chrono::seconds(tv.tv_sec)) +
std::chrono::steady_clock::duration(std::chrono::microseconds(tv.tv_usec));
}
...@@ -67,4 +67,8 @@ gcc_pure ...@@ -67,4 +67,8 @@ gcc_pure
std::chrono::system_clock::time_point std::chrono::system_clock::time_point
MakeTime(struct tm &tm) noexcept; MakeTime(struct tm &tm) noexcept;
gcc_pure
std::chrono::steady_clock::duration
ToSteadyClockDuration(const struct timeval &tv) noexcept;
#endif #endif
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "AvahiPoll.hxx" #include "AvahiPoll.hxx"
#include "event/SocketMonitor.hxx" #include "event/SocketMonitor.hxx"
#include "event/TimerEvent.hxx" #include "event/TimerEvent.hxx"
#include "time/Convert.hxx"
static unsigned static unsigned
FromAvahiWatchEvent(AvahiWatchEvent e) FromAvahiWatchEvent(AvahiWatchEvent e)
...@@ -78,12 +79,6 @@ private: ...@@ -78,12 +79,6 @@ private:
} }
}; };
static constexpr std::chrono::steady_clock::duration
TimevalToChrono(const timeval &tv)
{
return std::chrono::seconds(tv.tv_sec) + std::chrono::microseconds(tv.tv_usec);
}
struct AvahiTimeout final { struct AvahiTimeout final {
TimerEvent timer; TimerEvent timer;
...@@ -97,12 +92,12 @@ public: ...@@ -97,12 +92,12 @@ public:
:timer(_loop, BIND_THIS_METHOD(OnTimeout)), :timer(_loop, BIND_THIS_METHOD(OnTimeout)),
callback(_callback), userdata(_userdata) { callback(_callback), userdata(_userdata) {
if (tv != nullptr) if (tv != nullptr)
timer.Schedule(TimevalToChrono(*tv)); timer.Schedule(ToSteadyClockDuration(*tv));
} }
static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) { static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) {
if (tv != nullptr) if (tv != nullptr)
t->timer.Schedule(TimevalToChrono(*tv)); t->timer.Schedule(ToSteadyClockDuration(*tv));
else else
t->timer.Cancel(); t->timer.Cancel();
} }
......
...@@ -67,6 +67,7 @@ else ...@@ -67,6 +67,7 @@ else
dependencies: [ dependencies: [
libavahi_client_dep, libavahi_client_dep,
dbus_dep, dbus_dep,
time_dep,
], ],
) )
......
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