]> git.mxchange.org Git - simgear.git/blobdiff - simgear/package/Root.cxx
HTTP request cancellation
[simgear.git] / simgear / package / Root.cxx
index 7f2e8ea80560bcbd576ee71b1742956151596324..785076530feed194e611c75e4edbe830d684decc 100644 (file)
@@ -226,6 +226,20 @@ void Root::makeHTTPRequest(HTTP::Request *req)
     d->httpPendingRequests.push_back(req);
 }
 
+void Root::cancelHTTPRequest(HTTP::Request *req, const std::string &reason)
+{
+    if (d->http) {
+        d->http->cancelRequest(req, reason);
+    }
+
+    std::deque<HTTP::Request_ptr>::iterator it = std::find(d->httpPendingRequests.begin(),
+                                                           d->httpPendingRequests.end(),
+                                                           req);
+    if (it != d->httpPendingRequests.end()) {
+        d->httpPendingRequests.erase(it);
+    }
+}
+
 Root::Root(const SGPath& aPath, const std::string& aVersion) :
     d(new RootPrivate)
 {
@@ -532,8 +546,10 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason)
         }
 
         // and remove it from the active collection
-        d->catalogs.erase(catIt);
-    }
+        if (catIt != d->catalogs.end()) {
+            d->catalogs.erase(catIt);
+        }
+    } // of catalog has errors case
 
     if (d->refreshing.empty()) {
         d->fireRefreshStatus(CatalogRef(), Delegate::STATUS_REFRESHED);