Modernize client code (#6250)
[oweals/minetest.git] / src / httpfetch.cpp
index f64c9f717a62c36f9e976da22e98a363532684f0..cd66a80d51566969541966a69138cf6923893c80 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <list>
 #include <map>
 #include <errno.h>
+#include <mutex>
 #include "threading/event.h"
 #include "config.h"
 #include "exceptions.h"
@@ -36,20 +37,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "noise.h"
 
-Mutex g_httpfetch_mutex;
+std::mutex g_httpfetch_mutex;
 std::map<unsigned long, std::queue<HTTPFetchResult> > g_httpfetch_results;
 PcgRandom g_callerid_randomness;
 
-HTTPFetchRequest::HTTPFetchRequest()
+HTTPFetchRequest::HTTPFetchRequest() :
+       timeout(g_settings->getS32("curl_timeout")),
+       connect_timeout(timeout),
+       useragent(std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")")
 {
-       url = "";
-       caller = HTTPFETCH_DISCARD;
-       request_id = 0;
-       timeout = g_settings->getS32("curl_timeout");
-       connect_timeout = timeout;
-       multipart = false;
-
-       useragent = std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")";
 }
 
 
@@ -207,7 +203,7 @@ public:
 class HTTPFetchOngoing
 {
 public:
-       HTTPFetchOngoing(HTTPFetchRequest request, CurlHandlePool *pool);
+       HTTPFetchOngoing(const HTTPFetchRequest &request, CurlHandlePool *pool);
        ~HTTPFetchOngoing();
 
        CURLcode start(CURLM *multi);
@@ -228,7 +224,8 @@ private:
 };
 
 
-HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *pool_):
+HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
+               CurlHandlePool *pool_):
        pool(pool_),
        curl(NULL),
        multi(NULL),