diff --git a/src/https.cpp b/src/https.cpp index fb1e1a092..5ed34f647 100644 --- a/src/https.cpp +++ b/src/https.cpp @@ -49,6 +49,9 @@ struct thread_pool { private: void main_loop() { + CURL* curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); while (!terminate_all) { job j; { @@ -60,11 +63,12 @@ struct thread_pool { j = jobs.front(); jobs.pop(); } - handle_job(j); + handle_job(j,curl); } + curl_easy_cleanup(curl); } - void handle_job(job& j); + void handle_job(job& j, CURL* curl); std::atomic_bool terminate_all = { false }; @@ -188,9 +192,8 @@ CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) return rv; } -void thread_pool::handle_job(job& j) +void thread_pool::handle_job(job& j, CURL * curl) { - CURL* curl = curl_easy_init(); if (!curl) { printf("[cloud] failed to initialize curl\n"); @@ -259,7 +262,6 @@ void thread_pool::handle_job(job& j) } curl_slist_free_all(chunk); - curl_easy_cleanup(curl); } #endif