lib/upnp/Discovery: use std::chrono::steady_clock
This commit is contained in:
parent
4e60ab7f53
commit
cd607cb280
@ -20,7 +20,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Discovery.hxx"
|
#include "Discovery.hxx"
|
||||||
#include "ContentDirectoryService.hxx"
|
#include "ContentDirectoryService.hxx"
|
||||||
#include "system/Clock.hxx"
|
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
@ -132,7 +131,8 @@ UPnPDeviceDirectory::Explore()
|
|||||||
|
|
||||||
// Update or insert the device
|
// Update or insert the device
|
||||||
ContentDirectoryDescriptor d(std::move(tsk->device_id),
|
ContentDirectoryDescriptor d(std::move(tsk->device_id),
|
||||||
MonotonicClockS(), tsk->expires);
|
std::chrono::steady_clock::now(),
|
||||||
|
tsk->expires);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
d.Parse(tsk->url, buf);
|
d.Parse(tsk->url, buf);
|
||||||
@ -209,7 +209,7 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp)
|
|||||||
void
|
void
|
||||||
UPnPDeviceDirectory::ExpireDevices()
|
UPnPDeviceDirectory::ExpireDevices()
|
||||||
{
|
{
|
||||||
const unsigned now = MonotonicClockS();
|
const auto now = std::chrono::steady_clock::now();
|
||||||
bool didsomething = false;
|
bool didsomething = false;
|
||||||
|
|
||||||
for (auto it = directories.begin();
|
for (auto it = directories.begin();
|
||||||
@ -251,8 +251,8 @@ UPnPDeviceDirectory::Start()
|
|||||||
void
|
void
|
||||||
UPnPDeviceDirectory::Search()
|
UPnPDeviceDirectory::Search()
|
||||||
{
|
{
|
||||||
const unsigned now = MonotonicClockS();
|
const auto now = std::chrono::steady_clock::now();
|
||||||
if (now - last_search < 10)
|
if (now - last_search < std::chrono::seconds(10))
|
||||||
return;
|
return;
|
||||||
last_search = now;
|
last_search = now;
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
class ContentDirectoryService;
|
class ContentDirectoryService;
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
|
|||||||
struct DiscoveredTask {
|
struct DiscoveredTask {
|
||||||
std::string url;
|
std::string url;
|
||||||
std::string device_id;
|
std::string device_id;
|
||||||
unsigned expires; // Seconds valid
|
std::chrono::steady_clock::duration expires;
|
||||||
|
|
||||||
DiscoveredTask(const Upnp_Discovery *disco)
|
DiscoveredTask(const Upnp_Discovery *disco)
|
||||||
:url(disco->Location),
|
:url(disco->Location),
|
||||||
@ -75,16 +76,17 @@ class UPnPDeviceDirectory final : UpnpCallback {
|
|||||||
UPnPDevice device;
|
UPnPDevice device;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The MonotonicClockS() time stamp when this device
|
* The time stamp when this device expires.
|
||||||
* expires.
|
|
||||||
*/
|
*/
|
||||||
unsigned expires;
|
std::chrono::steady_clock::time_point expires;
|
||||||
|
|
||||||
ContentDirectoryDescriptor() = default;
|
ContentDirectoryDescriptor() = default;
|
||||||
|
|
||||||
ContentDirectoryDescriptor(std::string &&_id,
|
ContentDirectoryDescriptor(std::string &&_id,
|
||||||
unsigned last, int exp)
|
std::chrono::steady_clock::time_point last,
|
||||||
:id(std::move(_id)), expires(last + exp + 20) {}
|
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) {
|
void Parse(const std::string &url, const char *description) {
|
||||||
device.Parse(url, description);
|
device.Parse(url, description);
|
||||||
@ -106,9 +108,9 @@ class UPnPDeviceDirectory final : UpnpCallback {
|
|||||||
int search_timeout = 2;
|
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:
|
public:
|
||||||
UPnPDeviceDirectory(UpnpClient_Handle _handle,
|
UPnPDeviceDirectory(UpnpClient_Handle _handle,
|
||||||
|
Loading…
Reference in New Issue
Block a user