From cd607cb2809c2307348b649940ac81ad0f4d270f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 28 Dec 2016 22:03:19 +0100 Subject: [PATCH] lib/upnp/Discovery: use std::chrono::steady_clock --- src/lib/upnp/Discovery.cxx | 10 +++++----- src/lib/upnp/Discovery.hxx | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 3821e6d0d..52d5b21e1 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -20,7 +20,6 @@ #include "config.h" #include "Discovery.hxx" #include "ContentDirectoryService.hxx" -#include "system/Clock.hxx" #include "Log.hxx" #include "util/ScopeExit.hxx" #include "util/RuntimeError.hxx" @@ -132,7 +131,8 @@ UPnPDeviceDirectory::Explore() // Update or insert the device ContentDirectoryDescriptor d(std::move(tsk->device_id), - MonotonicClockS(), tsk->expires); + std::chrono::steady_clock::now(), + tsk->expires); try { d.Parse(tsk->url, buf); @@ -209,7 +209,7 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp) void UPnPDeviceDirectory::ExpireDevices() { - const unsigned now = MonotonicClockS(); + const auto now = std::chrono::steady_clock::now(); bool didsomething = false; for (auto it = directories.begin(); @@ -251,8 +251,8 @@ UPnPDeviceDirectory::Start() void UPnPDeviceDirectory::Search() { - const unsigned now = MonotonicClockS(); - if (now - last_search < 10) + const auto now = std::chrono::steady_clock::now(); + if (now - last_search < std::chrono::seconds(10)) return; last_search = now; diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index eb3b308be..71ce75be6 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -32,6 +32,7 @@ #include #include #include +#include class ContentDirectoryService; @@ -56,7 +57,7 @@ class UPnPDeviceDirectory final : UpnpCallback { struct DiscoveredTask { std::string url; std::string device_id; - unsigned expires; // Seconds valid + std::chrono::steady_clock::duration expires; DiscoveredTask(const Upnp_Discovery *disco) :url(disco->Location), @@ -75,16 +76,17 @@ class UPnPDeviceDirectory final : UpnpCallback { UPnPDevice device; /** - * The MonotonicClockS() time stamp when this device - * expires. + * The time stamp when this device expires. */ - unsigned expires; + std::chrono::steady_clock::time_point expires; ContentDirectoryDescriptor() = default; ContentDirectoryDescriptor(std::string &&_id, - unsigned last, int exp) - :id(std::move(_id)), expires(last + exp + 20) {} + std::chrono::steady_clock::time_point last, + std::chrono::steady_clock::duration exp) + :id(std::move(_id)), + expires(last + exp + std::chrono::seconds(20)) {} void Parse(const std::string &url, const char *description) { device.Parse(url, description); @@ -106,9 +108,9 @@ class UPnPDeviceDirectory final : UpnpCallback { int search_timeout = 2; /** - * The MonotonicClockS() time stamp of the last search. + * The time stamp of the last search. */ - unsigned last_search = 0; + std::chrono::steady_clock::time_point last_search = std::chrono::steady_clock::time_point(); public: UPnPDeviceDirectory(UpnpClient_Handle _handle,