aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/networking/curl/connectionmanager.cpp18
-rw-r--r--backends/networking/curl/connectionmanager.h2
-rw-r--r--base/main.cpp6
3 files changed, 24 insertions, 2 deletions
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index ef3c858bec..a3cad0d005 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -43,6 +43,19 @@ ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false) {
}
ConnectionManager::~ConnectionManager() {
+ //terminate all requests
+ _handleMutex.lock();
+ for (Common::Array<RequestWithCallback>::iterator i = _requests.begin(); i != _requests.end(); ++i) {
+ Request *request = i->request;
+ RequestCallback callback = i->callback;
+ if (request) request->finish();
+ delete request;
+ if (callback) (*callback)(request);
+ }
+ _requests.clear();
+ _handleMutex.unlock();
+
+ //cleanup
curl_multi_cleanup(_multi);
curl_global_cleanup();
}
@@ -80,10 +93,11 @@ void ConnectionManager::stopTimer() {
}
void ConnectionManager::handle() {
- //TODO: lock mutex here (in case another handle() would be called before this one ends)
+ //lock mutex here (in case another handle() would be called before this one ends)
+ _handleMutex.lock();
interateRequests();
processTransfers();
- //TODO: unlock mutex here
+ _handleMutex.unlock();
}
void ConnectionManager::interateRequests() {
diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h
index b39a779558..75cff0587b 100644
--- a/backends/networking/curl/connectionmanager.h
+++ b/backends/networking/curl/connectionmanager.h
@@ -27,6 +27,7 @@
#include "common/str.h"
#include "common/singleton.h"
#include "common/hashmap.h"
+#include "common/mutex.h"
typedef void CURL;
typedef void CURLM;
@@ -51,6 +52,7 @@ class ConnectionManager : public Common::Singleton<ConnectionManager> {
CURLM *_multi;
bool _timerStarted;
Common::Array<RequestWithCallback> _requests;
+ Common::Mutex _handleMutex;
void startTimer(int interval = 1000000); //1 second is the default interval
void stopTimer();
diff --git a/base/main.cpp b/base/main.cpp
index 36dd8c6f18..aede61790c 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -67,6 +67,9 @@
#include "backends/keymapper/keymapper.h"
#include "common/cloudmanager.h"
+#ifdef USE_LIBCURL
+#include "backends/networking/curl/connectionmanager.h"
+#endif
#if defined(_WIN32_WCE)
#include "backends/platform/wince/CELauncherDialog.h"
@@ -591,6 +594,9 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
launcherDialog();
}
}
+#ifdef USE_LIBCURL
+ Networking::ConnectionManager::destroy();
+#endif
PluginManager::instance().unloadAllPlugins();
PluginManager::destroy();
GUI::GuiManager::destroy();