]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/httpfetch.cpp
Add support for named threads (atm linux only)
[dragonfireclient.git] / src / httpfetch.cpp
index 60e4591a921444c57137dbc14f72bdebee124350..751a4471a811cab1faeb94ed9d98bcbac9f16b1c 100644 (file)
@@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "socket.h" // for select()
-#include "porting.h" // for sleep_ms()
+#include "porting.h" // for sleep_ms(), get_sysinfo()
 #include "httpfetch.h"
 #include <iostream>
 #include <sstream>
@@ -32,10 +32,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 #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;
 
+HTTPFetchRequest::HTTPFetchRequest()
+{
+       url = "";
+       caller = HTTPFETCH_DISCARD;
+       request_id = 0;
+       timeout = g_settings->getS32("curl_timeout");
+       connect_timeout = timeout * 5;
+       
+       useragent = std::string("Minetest/") + minetest_version_hash + " (" + porting::get_sysinfo() + ")";
+}
+
+
 static void httpfetch_deliver_result(const HTTPFetchResult &fetchresult)
 {
        unsigned long caller = fetchresult.caller;
@@ -523,7 +538,7 @@ class CurlFetchThread : public JThread
                if (select_timeout > 0) {
                        // in Winsock it is forbidden to pass three empty
                        // fd_sets to select(), so in that case use sleep_ms
-                       if (max_fd == -1) {
+                       if (max_fd != -1) {
                                select_tv.tv_sec = select_timeout / 1000;
                                select_tv.tv_usec = (select_timeout % 1000) * 1000;
                                int retval = select(max_fd + 1, &read_fd_set,
@@ -551,6 +566,8 @@ class CurlFetchThread : public JThread
                log_register_thread("CurlFetchThread");
                DSTACK(__FUNCTION_NAME);
 
+               porting::setThreadName("CurlFetchThread");
+
                CurlHandlePool pool;
 
                m_multi = curl_multi_init();
@@ -569,7 +586,7 @@ class CurlFetchThread : public JThread
                        */
 
                        while (!m_requests.empty()) {
-                               Request req = m_requests.pop_front();
+                               Request req = m_requests.pop_frontNoEx();
                                processRequest(req);
                        }
                        processQueued(&pool);