diff --git a/src/upnp/protocol/pupnp/pupnp.cpp b/src/upnp/protocol/pupnp/pupnp.cpp index 7652c2e3cbd14622219267bd994f450c5345e62f..9c02fdc7db51b0162d629be5a20705e7cdf4cd3e 100644 --- a/src/upnp/protocol/pupnp/pupnp.cpp +++ b/src/upnp/protocol/pupnp/pupnp.cpp @@ -171,8 +171,8 @@ PUPnP::PUPnP() } lk.lock(); - // Move back failed items to end of list - dwnldlXmlList_.splice(dwnldlXmlList_.end(), xmlList); + // Move back timed-out items to list + dwnldlXmlList_.splice(dwnldlXmlList_.begin(), xmlList); // Handle successful downloads for (auto& item : finished) { auto result = item.get(); @@ -181,6 +181,13 @@ PUPnP::PUPnP() } } } + for (auto it = cancelXmlList_.begin(); it != cancelXmlList_.end();) { + if (it->wait_for(std::chrono::seconds(0)) == std::future_status::ready) { + it = cancelXmlList_.erase(it); + } else { + ++it; + } + } } } @@ -201,6 +208,7 @@ PUPnP::~PUPnP() validIgdList_.clear(); cpDeviceList_.clear(); dwnldlXmlList_.clear(); + cancelXmlList_.clear(); } // Notify thread to terminate. UpnpFinish function will get called. @@ -217,7 +225,7 @@ PUPnP::clearIgds() std::lock_guard<std::mutex> lk(validIgdMutex_); // Clear all internal lists. - dwnldlXmlList_.clear(); + cancelXmlList_.splice(cancelXmlList_.end(), dwnldlXmlList_); validIgdList_.clear(); cpDeviceList_.clear(); } diff --git a/src/upnp/protocol/pupnp/pupnp.h b/src/upnp/protocol/pupnp/pupnp.h index 2d2a95024bf1cb3d27edc77a7fcee5fc23d9f69d..77c136ddc938904688b7bd68a7c2c4ec79564a00 100644 --- a/src/upnp/protocol/pupnp/pupnp.h +++ b/src/upnp/protocol/pupnp/pupnp.h @@ -147,7 +147,8 @@ private: std::map<std::string, std::shared_ptr<IGD>> validIgdList_; // Map of valid IGDs with their UDN (universal Id). std::set<std::string> cpDeviceList_; // Control point device list containing the device ID and device subscription event url. - std::list<std::future<pIGDInfo>> dwnldlXmlList_; // List of shared_futures for blocking xml download function calls. + std::list<std::future<pIGDInfo>> dwnldlXmlList_; // List of futures for blocking xml download function calls. + std::list<std::future<pIGDInfo>> cancelXmlList_; // List of abandoned documents std::mutex ctrlptMutex_; // Mutex for client handle protection. UpnpClient_Handle ctrlptHandle_ {-1}; // Control point handle.