db/upnp/Discovery: use monotonic clock instead of time()
This commit is contained in:
parent
0696cac50b
commit
051eede1ed
|
@ -22,6 +22,7 @@
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "ContentDirectoryService.hxx"
|
#include "ContentDirectoryService.hxx"
|
||||||
#include "upnpplib.hxx"
|
#include "upnpplib.hxx"
|
||||||
|
#include "system/Clock.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <upnp/upnptools.h>
|
#include <upnp/upnptools.h>
|
||||||
|
@ -74,7 +75,7 @@ UPnPDeviceDirectory::discoExplorer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update or insert the device
|
// Update or insert the device
|
||||||
ContentDirectoryDescriptor d(time(0), tsk->expires);
|
ContentDirectoryDescriptor d(MonotonicClockS(), tsk->expires);
|
||||||
|
|
||||||
{
|
{
|
||||||
Error error2;
|
Error error2;
|
||||||
|
@ -164,7 +165,7 @@ bool
|
||||||
UPnPDeviceDirectory::expireDevices(Error &error)
|
UPnPDeviceDirectory::expireDevices(Error &error)
|
||||||
{
|
{
|
||||||
const ScopeLock protect(mutex);
|
const ScopeLock protect(mutex);
|
||||||
time_t now = time(0);
|
const unsigned now = MonotonicClockS();
|
||||||
bool didsomething = false;
|
bool didsomething = false;
|
||||||
|
|
||||||
for (auto it = directories.begin();
|
for (auto it = directories.begin();
|
||||||
|
@ -208,7 +209,7 @@ UPnPDeviceDirectory::Start(Error &error)
|
||||||
bool
|
bool
|
||||||
UPnPDeviceDirectory::search(Error &error)
|
UPnPDeviceDirectory::search(Error &error)
|
||||||
{
|
{
|
||||||
time_t now = time(0);
|
const unsigned now = MonotonicClockS();
|
||||||
if (now - m_lastSearch < 10)
|
if (now - m_lastSearch < 10)
|
||||||
return true;
|
return true;
|
||||||
m_lastSearch = now;
|
m_lastSearch = now;
|
||||||
|
|
|
@ -31,8 +31,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
class LibUPnP;
|
class LibUPnP;
|
||||||
class ContentDirectoryService;
|
class ContentDirectoryService;
|
||||||
|
|
||||||
|
@ -51,7 +49,7 @@ class UPnPDeviceDirectory {
|
||||||
struct DiscoveredTask {
|
struct DiscoveredTask {
|
||||||
std::string url;
|
std::string url;
|
||||||
std::string deviceId;
|
std::string deviceId;
|
||||||
int expires; // Seconds valid
|
unsigned expires; // Seconds valid
|
||||||
|
|
||||||
DiscoveredTask(const Upnp_Discovery *disco)
|
DiscoveredTask(const Upnp_Discovery *disco)
|
||||||
:url(disco->Location),
|
:url(disco->Location),
|
||||||
|
@ -66,12 +64,18 @@ class UPnPDeviceDirectory {
|
||||||
class ContentDirectoryDescriptor {
|
class ContentDirectoryDescriptor {
|
||||||
public:
|
public:
|
||||||
UPnPDevice device;
|
UPnPDevice device;
|
||||||
time_t last_seen;
|
|
||||||
int expires; // seconds valid
|
/**
|
||||||
|
* The MonotonicClockS() time stamp when this device
|
||||||
|
* was last seen alive.
|
||||||
|
*/
|
||||||
|
unsigned last_seen;
|
||||||
|
|
||||||
|
unsigned expires; // seconds valid
|
||||||
|
|
||||||
ContentDirectoryDescriptor() = default;
|
ContentDirectoryDescriptor() = default;
|
||||||
|
|
||||||
ContentDirectoryDescriptor(time_t last, int exp)
|
ContentDirectoryDescriptor(unsigned last, int exp)
|
||||||
:last_seen(last), expires(exp+20) {}
|
:last_seen(last), expires(exp+20) {}
|
||||||
|
|
||||||
bool Parse(const std::string &url, const char *description,
|
bool Parse(const std::string &url, const char *description,
|
||||||
|
@ -93,7 +97,10 @@ class UPnPDeviceDirectory {
|
||||||
*/
|
*/
|
||||||
int m_searchTimeout;
|
int m_searchTimeout;
|
||||||
|
|
||||||
time_t m_lastSearch;
|
/**
|
||||||
|
* The MonotonicClockS() time stamp of the last search.
|
||||||
|
*/
|
||||||
|
unsigned m_lastSearch;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPnPDeviceDirectory(LibUPnP *_lib);
|
UPnPDeviceDirectory(LibUPnP *_lib);
|
||||||
|
|
Loading…
Reference in New Issue