diff options
author | Max Kellermann <max@musicpd.org> | 2019-05-08 16:11:14 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-12-16 23:02:45 +0100 |
commit | ae35df1126198d5d20bbd3c3a37c731bf5d3b388 (patch) | |
tree | bc13ffba0b3763063307654a6bad05f2846899d3 /src | |
parent | 80e55f6bfc8be136af0f603c6c6b9c3b3b435a7b (diff) |
zeroconf/AvahiPoll: move TimevalToChrono() to time/Convert.cxx
Diffstat (limited to 'src')
-rw-r--r-- | src/time/Convert.cxx | 7 | ||||
-rw-r--r-- | src/time/Convert.hxx | 4 | ||||
-rw-r--r-- | src/zeroconf/AvahiPoll.cxx | 11 | ||||
-rw-r--r-- | src/zeroconf/meson.build | 1 |
4 files changed, 15 insertions, 8 deletions
diff --git a/src/time/Convert.cxx b/src/time/Convert.cxx index fcb19dbe5..044cfd303 100644 --- a/src/time/Convert.cxx +++ b/src/time/Convert.cxx @@ -81,3 +81,10 @@ MakeTime(struct tm &tm) noexcept { 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)); +} diff --git a/src/time/Convert.hxx b/src/time/Convert.hxx index a84ecdf02..558bd2e37 100644 --- a/src/time/Convert.hxx +++ b/src/time/Convert.hxx @@ -67,4 +67,8 @@ gcc_pure std::chrono::system_clock::time_point MakeTime(struct tm &tm) noexcept; +gcc_pure +std::chrono::steady_clock::duration +ToSteadyClockDuration(const struct timeval &tv) noexcept; + #endif diff --git a/src/zeroconf/AvahiPoll.cxx b/src/zeroconf/AvahiPoll.cxx index eeb669b23..cc62e67e4 100644 --- a/src/zeroconf/AvahiPoll.cxx +++ b/src/zeroconf/AvahiPoll.cxx @@ -20,6 +20,7 @@ #include "AvahiPoll.hxx" #include "event/SocketMonitor.hxx" #include "event/TimerEvent.hxx" +#include "time/Convert.hxx" static unsigned FromAvahiWatchEvent(AvahiWatchEvent e) @@ -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 { TimerEvent timer; @@ -97,12 +92,12 @@ public: :timer(_loop, BIND_THIS_METHOD(OnTimeout)), callback(_callback), userdata(_userdata) { if (tv != nullptr) - timer.Schedule(TimevalToChrono(*tv)); + timer.Schedule(ToSteadyClockDuration(*tv)); } static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) { if (tv != nullptr) - t->timer.Schedule(TimevalToChrono(*tv)); + t->timer.Schedule(ToSteadyClockDuration(*tv)); else t->timer.Cancel(); } diff --git a/src/zeroconf/meson.build b/src/zeroconf/meson.build index 2858079cb..c2853b344 100644 --- a/src/zeroconf/meson.build +++ b/src/zeroconf/meson.build @@ -67,6 +67,7 @@ else dependencies: [ libavahi_client_dep, dbus_dep, + time_dep, ], ) |