Commit a2589498 authored by Adrien Béraud's avatar Adrien Béraud

pupnp: don't block on futures on connectivity change

Change-Id: I4e05d780481c340e288fcbb56898f30fb40bf90c
parent 24bbdc57
...@@ -171,8 +171,8 @@ PUPnP::PUPnP() ...@@ -171,8 +171,8 @@ PUPnP::PUPnP()
} }
lk.lock(); lk.lock();
// Move back failed items to end of list // Move back timed-out items to list
dwnldlXmlList_.splice(dwnldlXmlList_.end(), xmlList); dwnldlXmlList_.splice(dwnldlXmlList_.begin(), xmlList);
// Handle successful downloads // Handle successful downloads
for (auto& item : finished) { for (auto& item : finished) {
auto result = item.get(); auto result = item.get();
...@@ -181,6 +181,13 @@ PUPnP::PUPnP() ...@@ -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() ...@@ -201,6 +208,7 @@ PUPnP::~PUPnP()
validIgdList_.clear(); validIgdList_.clear();
cpDeviceList_.clear(); cpDeviceList_.clear();
dwnldlXmlList_.clear(); dwnldlXmlList_.clear();
cancelXmlList_.clear();
} }
// Notify thread to terminate. UpnpFinish function will get called. // Notify thread to terminate. UpnpFinish function will get called.
...@@ -217,7 +225,7 @@ PUPnP::clearIgds() ...@@ -217,7 +225,7 @@ PUPnP::clearIgds()
std::lock_guard<std::mutex> lk(validIgdMutex_); std::lock_guard<std::mutex> lk(validIgdMutex_);
// Clear all internal lists. // Clear all internal lists.
dwnldlXmlList_.clear(); cancelXmlList_.splice(cancelXmlList_.end(), dwnldlXmlList_);
validIgdList_.clear(); validIgdList_.clear();
cpDeviceList_.clear(); cpDeviceList_.clear();
} }
......
...@@ -147,7 +147,8 @@ private: ...@@ -147,7 +147,8 @@ private:
std::map<std::string, std::shared_ptr<IGD>> validIgdList_; // Map of valid IGDs with their UDN (universal Id). 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::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. std::mutex ctrlptMutex_; // Mutex for client handle protection.
UpnpClient_Handle ctrlptHandle_ {-1}; // Control point handle. UpnpClient_Handle ctrlptHandle_ {-1}; // Control point handle.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment