diff options
author | Alexander Tkachev | 2016-05-26 17:56:13 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 62ccf1f902100febfb1be02b67e84a6e4938ebbf (patch) | |
tree | 1f86b079605ac27d897ae9fc3f9e6cc84e8bf205 /backends/networking/curl/connectionmanager.cpp | |
parent | eda575a660543884b1a4addd21b676a67d2c2a31 (diff) | |
download | scummvm-rg350-62ccf1f902100febfb1be02b67e84a6e4938ebbf.tar.gz scummvm-rg350-62ccf1f902100febfb1be02b67e84a6e4938ebbf.tar.bz2 scummvm-rg350-62ccf1f902100febfb1be02b67e84a6e4938ebbf.zip |
CLOUD: Add RequestInfo struct
ConnectionManager upgrade: it now contains a special struct for each
request, so you can access request status and data by request id.
Diffstat (limited to 'backends/networking/curl/connectionmanager.cpp')
-rw-r--r-- | backends/networking/curl/connectionmanager.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index 8428bd25f0..b448d8e514 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -50,12 +50,16 @@ void ConnectionManager::registerEasyHandle(CURL *easy) { int32 ConnectionManager::addRequest(Request *request) { int32 newId = _nextId++; - _requests[newId] = request; + _requests[newId] = RequestInfo(newId, request); request->setId(newId); if (!_timerStarted) startTimer(); return newId; } +RequestInfo &ConnectionManager::getRequestInfo(int32 id) { + return _requests[id]; +} + //private goes here: void connectionsThread(void *ignored) { @@ -87,15 +91,34 @@ void ConnectionManager::handle() { void ConnectionManager::interateRequests() { //call handle() of all running requests (so they can do their work) debug("handling %d request(s)", _requests.size()); - for (Common::HashMap<int32, Request *>::iterator i = _requests.begin(); i != _requests.end();) { - Request *request = i->_value; - if (request && request->handle()) { - delete request; - //_requests.erase(i); - _requests[i->_key] = 0; - ++i; //that's temporary - } else ++i; + Common::Array<int32> idsToRemove; + for (Common::HashMap<int32, RequestInfo>::iterator i = _requests.begin(); i != _requests.end(); ++i) { + RequestInfo &info = _requests[i->_key]; + + switch(info.state) { + case FINISHED: + delete info.request; + info.request = 0; + idsToRemove.push_back(info.id); + break; + + case PROCESSING: + info.request->handle(); + break; + + case RETRY: + if (info.retryInSeconds > 0) --info.retryInSeconds; + else { + info.state = PROCESSING; + info.request->restart(); + } + + default: + ; //nothing to do + } } + for (uint32 i = 0; i < idsToRemove.size(); ++i) + _requests.erase(idsToRemove[i]); if (_requests.empty()) stopTimer(); } |