From e5ee357903addb3301198c2624dc0115054c833e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 25 Aug 2017 11:01:30 +0200 Subject: [PATCH] lib/upnp/Discovery: use DeferredMonitor instead of BlockingCall() --- src/lib/upnp/Discovery.cxx | 19 +++++++------------ src/lib/upnp/Discovery.hxx | 11 +++++++++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 2d2f4ff02..a9ea0a6c7 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -22,7 +22,6 @@ #include "ContentDirectoryService.hxx" #include "Log.hxx" #include "lib/curl/Global.hxx" -#include "event/Call.hxx" #include "util/DeleteDisposer.hxx" #include "util/ScopeExit.hxx" #include "util/RuntimeError.hxx" @@ -34,7 +33,7 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, const Upnp_Discovery &disco) - :parent(_parent), + :DeferredMonitor(_parent.GetEventLoop()), parent(_parent), id(disco.DeviceId), url(disco.Location), expires(std::chrono::seconds(disco.Expires)), request(*parent.curl, url.c_str(), *this) @@ -42,16 +41,6 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, parent.downloaders.push_back(*this); } -void -UPnPDeviceDirectory::Downloader::Start() -{ - auto &event_loop = parent.GetEventLoop(); - - BlockingCall(event_loop, [this](){ - request.Start(); - }); -} - void UPnPDeviceDirectory::Downloader::Destroy() { @@ -59,6 +48,12 @@ UPnPDeviceDirectory::Downloader::Destroy() DeleteDisposer()); } +void +UPnPDeviceDirectory::Downloader::RunDeferred() +{ + request.Start(); +} + void UPnPDeviceDirectory::Downloader::OnHeaders(unsigned status, std::multimap &&) diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 2e59be3c4..f34bc3c39 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -26,6 +26,7 @@ #include "lib/curl/Handler.hxx" #include "lib/curl/Request.hxx" #include "thread/Mutex.hxx" +#include "event/DeferredMonitor.hxx" #include "Compiler.h" #include @@ -83,7 +84,7 @@ class UPnPDeviceDirectory final : UpnpCallback { class Downloader final : public boost::intrusive::list_base_hook>, - CurlResponseHandler { + DeferredMonitor, CurlResponseHandler { UPnPDeviceDirectory &parent; @@ -99,10 +100,16 @@ class UPnPDeviceDirectory final : UpnpCallback { Downloader(UPnPDeviceDirectory &_parent, const Upnp_Discovery &disco); - void Start(); + void Start() { + DeferredMonitor::Schedule(); + } + void Destroy(); private: + /* virtual methods from DeferredMonitor */ + void RunDeferred() override; + /* virtual methods from CurlResponseHandler */ void OnHeaders(unsigned status, std::multimap &&headers) override;