summaryrefslogtreecommitdiff
path: root/src/httpfetch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/httpfetch.cpp')
-rw-r--r--src/httpfetch.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp
index 47e33480b..56cdad2b1 100644
--- a/src/httpfetch.cpp
+++ b/src/httpfetch.cpp
@@ -33,11 +33,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/container.h"
#include "util/thread.h"
#include "version.h"
-#include "main.h"
#include "settings.h"
JMutex g_httpfetch_mutex;
-std::map<unsigned long, std::list<HTTPFetchResult> > g_httpfetch_results;
+std::map<unsigned long, std::queue<HTTPFetchResult> > g_httpfetch_results;
HTTPFetchRequest::HTTPFetchRequest()
{
@@ -48,7 +47,7 @@ HTTPFetchRequest::HTTPFetchRequest()
connect_timeout = timeout;
multipart = false;
- useragent = std::string("Minetest/") + minetest_version_hash + " (" + porting::get_sysinfo() + ")";
+ useragent = std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")";
}
@@ -57,7 +56,7 @@ static void httpfetch_deliver_result(const HTTPFetchResult &fetch_result)
unsigned long caller = fetch_result.caller;
if (caller != HTTPFETCH_DISCARD) {
JMutexAutoLock lock(g_httpfetch_mutex);
- g_httpfetch_results[caller].push_back(fetch_result);
+ g_httpfetch_results[caller].push(fetch_result);
}
}
@@ -70,18 +69,18 @@ unsigned long httpfetch_caller_alloc()
// Check each caller ID except HTTPFETCH_DISCARD
const unsigned long discard = HTTPFETCH_DISCARD;
for (unsigned long caller = discard + 1; caller != discard; ++caller) {
- std::map<unsigned long, std::list<HTTPFetchResult> >::iterator
+ std::map<unsigned long, std::queue<HTTPFetchResult> >::iterator
it = g_httpfetch_results.find(caller);
if (it == g_httpfetch_results.end()) {
- verbosestream<<"httpfetch_caller_alloc: allocating "
- <<caller<<std::endl;
+ verbosestream << "httpfetch_caller_alloc: allocating "
+ << caller << std::endl;
// Access element to create it
g_httpfetch_results[caller];
return caller;
}
}
- assert("httpfetch_caller_alloc: ran out of caller IDs" == 0);
+ FATAL_ERROR("httpfetch_caller_alloc: ran out of caller IDs");
return discard;
}
@@ -102,19 +101,19 @@ bool httpfetch_async_get(unsigned long caller, HTTPFetchResult &fetch_result)
JMutexAutoLock lock(g_httpfetch_mutex);
// Check that caller exists
- std::map<unsigned long, std::list<HTTPFetchResult> >::iterator
+ std::map<unsigned long, std::queue<HTTPFetchResult> >::iterator
it = g_httpfetch_results.find(caller);
if (it == g_httpfetch_results.end())
return false;
// Check that result queue is nonempty
- std::list<HTTPFetchResult> &caller_results = it->second;
+ std::queue<HTTPFetchResult> &caller_results = it->second;
if (caller_results.empty())
return false;
// Pop first result
fetch_result = caller_results.front();
- caller_results.pop_front();
+ caller_results.pop();
return true;
}
@@ -194,7 +193,6 @@ private:
HTTPFetchRequest request;
HTTPFetchResult result;
std::ostringstream oss;
- char *post_fields;
struct curl_slist *http_header;
curl_httppost *post;
};
@@ -268,8 +266,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
} else if (request.multipart) {
curl_httppost *last = NULL;
- for (std::map<std::string, std::string>::iterator it =
- request.post_fields.begin();
+ for (StringMap::iterator it = request.post_fields.begin();
it != request.post_fields.end(); ++it) {
curl_formadd(&post, &last,
CURLFORM_NAMELENGTH, it->first.size(),
@@ -284,10 +281,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
} else if (request.post_data.empty()) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
std::string str;
- for (std::map<std::string, std::string>::iterator it =
- request.post_fields.begin();
- it != request.post_fields.end();
- ++it) {
+ for (StringMap::iterator it = request.post_fields.begin();
+ it != request.post_fields.end(); ++it) {
if (str != "")
str += "&";
str += urlencode(it->first);
@@ -634,7 +629,7 @@ protected:
return NULL;
}
- assert(m_all_ongoing.empty());
+ FATAL_ERROR_IF(!m_all_ongoing.empty(), "Expected empty");
while (!StopRequested()) {
BEGIN_DEBUG_EXCEPTION_HANDLER
@@ -715,7 +710,7 @@ void httpfetch_init(int parallel_limit)
<<std::endl;
CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
- assert(res == CURLE_OK);
+ FATAL_ERROR_IF(res != CURLE_OK, "CURL init failed");
g_httpfetch_thread = new CurlFetchThread(parallel_limit);
}