lib/upnp/Discovery: use DeferredMonitor instead of BlockingCall()
This commit is contained in:
@@ -22,7 +22,6 @@
|
|||||||
#include "ContentDirectoryService.hxx"
|
#include "ContentDirectoryService.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "lib/curl/Global.hxx"
|
#include "lib/curl/Global.hxx"
|
||||||
#include "event/Call.hxx"
|
|
||||||
#include "util/DeleteDisposer.hxx"
|
#include "util/DeleteDisposer.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
@@ -34,7 +33,7 @@
|
|||||||
|
|
||||||
UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
|
UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
|
||||||
const Upnp_Discovery &disco)
|
const Upnp_Discovery &disco)
|
||||||
:parent(_parent),
|
:DeferredMonitor(_parent.GetEventLoop()), parent(_parent),
|
||||||
id(disco.DeviceId), url(disco.Location),
|
id(disco.DeviceId), url(disco.Location),
|
||||||
expires(std::chrono::seconds(disco.Expires)),
|
expires(std::chrono::seconds(disco.Expires)),
|
||||||
request(*parent.curl, url.c_str(), *this)
|
request(*parent.curl, url.c_str(), *this)
|
||||||
@@ -42,16 +41,6 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
|
|||||||
parent.downloaders.push_back(*this);
|
parent.downloaders.push_back(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
UPnPDeviceDirectory::Downloader::Start()
|
|
||||||
{
|
|
||||||
auto &event_loop = parent.GetEventLoop();
|
|
||||||
|
|
||||||
BlockingCall(event_loop, [this](){
|
|
||||||
request.Start();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
UPnPDeviceDirectory::Downloader::Destroy()
|
UPnPDeviceDirectory::Downloader::Destroy()
|
||||||
{
|
{
|
||||||
@@ -59,6 +48,12 @@ UPnPDeviceDirectory::Downloader::Destroy()
|
|||||||
DeleteDisposer());
|
DeleteDisposer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UPnPDeviceDirectory::Downloader::RunDeferred()
|
||||||
|
{
|
||||||
|
request.Start();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UPnPDeviceDirectory::Downloader::OnHeaders(unsigned status,
|
UPnPDeviceDirectory::Downloader::OnHeaders(unsigned status,
|
||||||
std::multimap<std::string, std::string> &&)
|
std::multimap<std::string, std::string> &&)
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "lib/curl/Handler.hxx"
|
#include "lib/curl/Handler.hxx"
|
||||||
#include "lib/curl/Request.hxx"
|
#include "lib/curl/Request.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
|
#include "event/DeferredMonitor.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <upnp/upnp.h>
|
#include <upnp/upnp.h>
|
||||||
@@ -83,7 +84,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
|
|||||||
|
|
||||||
class Downloader final
|
class Downloader final
|
||||||
: public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>,
|
: public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>,
|
||||||
CurlResponseHandler {
|
DeferredMonitor, CurlResponseHandler {
|
||||||
|
|
||||||
UPnPDeviceDirectory &parent;
|
UPnPDeviceDirectory &parent;
|
||||||
|
|
||||||
@@ -99,10 +100,16 @@ class UPnPDeviceDirectory final : UpnpCallback {
|
|||||||
Downloader(UPnPDeviceDirectory &_parent,
|
Downloader(UPnPDeviceDirectory &_parent,
|
||||||
const Upnp_Discovery &disco);
|
const Upnp_Discovery &disco);
|
||||||
|
|
||||||
void Start();
|
void Start() {
|
||||||
|
DeferredMonitor::Schedule();
|
||||||
|
}
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/* virtual methods from DeferredMonitor */
|
||||||
|
void RunDeferred() override;
|
||||||
|
|
||||||
/* virtual methods from CurlResponseHandler */
|
/* virtual methods from CurlResponseHandler */
|
||||||
void OnHeaders(unsigned status,
|
void OnHeaders(unsigned status,
|
||||||
std::multimap<std::string, std::string> &&headers) override;
|
std::multimap<std::string, std::string> &&headers) override;
|
||||||
|
Reference in New Issue
Block a user