diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 68cc5a6a3..341f710a4 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -6,7 +6,10 @@ #include "Log.hxx" #include "Error.hxx" #include "lib/curl/Global.hxx" +#include "lib/curl/Handler.hxx" +#include "lib/curl/Request.hxx" #include "event/Call.hxx" +#include "event/InjectEvent.hxx" #include "util/DeleteDisposer.hxx" #include "util/ScopeExit.hxx" #include "util/SpanCast.hxx" @@ -15,6 +18,47 @@ #include +class UPnPDeviceDirectory::Downloader final + : public IntrusiveListHook<>, CurlResponseHandler +{ + InjectEvent defer_start_event; + + UPnPDeviceDirectory &parent; + + std::string id; + const std::string url; + const std::chrono::steady_clock::duration expires; + + CurlRequest request; + + std::string data; + +public: + Downloader(UPnPDeviceDirectory &_parent, + const UpnpDiscovery &disco); + + void Start() noexcept { + defer_start_event.Schedule(); + } + + void Destroy() noexcept; + +private: + void OnDeferredStart() noexcept { + try { + request.Start(); + } catch (...) { + OnError(std::current_exception()); + } + } + + /* virtual methods from CurlResponseHandler */ + void OnHeaders(unsigned status, Curl::Headers &&headers) override; + void OnData(std::span data) override; + void OnEnd() override; + void OnError(std::exception_ptr e) noexcept override; +}; + UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, const UpnpDiscovery &disco) :defer_start_event(_parent.GetEventLoop(), diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 0cc85fd89..433481368 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -4,14 +4,9 @@ #include "Callback.hxx" #include "Device.hxx" #include "lib/curl/Init.hxx" -#include "lib/curl/Handler.hxx" -#include "lib/curl/Request.hxx" #include "thread/Mutex.hxx" -#include "event/InjectEvent.hxx" #include "util/IntrusiveList.hxx" -#include - #include #include #include @@ -60,46 +55,7 @@ class UPnPDeviceDirectory final : UpnpCallback { } }; - class Downloader final - : public IntrusiveListHook<>, CurlResponseHandler - { - InjectEvent defer_start_event; - - UPnPDeviceDirectory &parent; - - std::string id; - const std::string url; - const std::chrono::steady_clock::duration expires; - - CurlRequest request; - - std::string data; - - public: - Downloader(UPnPDeviceDirectory &_parent, - const UpnpDiscovery &disco); - - void Start() noexcept { - defer_start_event.Schedule(); - } - - void Destroy() noexcept; - - private: - void OnDeferredStart() noexcept { - try { - request.Start(); - } catch (...) { - OnError(std::current_exception()); - } - } - - /* virtual methods from CurlResponseHandler */ - void OnHeaders(unsigned status, Curl::Headers &&headers) override; - void OnData(std::span data) override; - void OnEnd() override; - void OnError(std::exception_ptr e) noexcept override; - }; + class Downloader; CurlInit curl;