diff --git a/src/client/http/Request.cpp b/src/client/http/Request.cpp index 9125bb7b3..4fa794f9d 100644 --- a/src/client/http/Request.cpp +++ b/src/client/http/Request.cpp @@ -85,6 +85,14 @@ namespace http } } + size_t Request::WriteDataHandler(char *ptr, size_t size, size_t count, void *userdata) + { + Request *req = (Request *)userdata; + auto actual_size = size * count; + req->response_body.append(ptr, actual_size); + return actual_size; + } + // start the request thread void Request::Start() { @@ -121,12 +129,7 @@ namespace http curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(easy, CURLOPT_WRITEDATA, (void *)this); - curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, (size_t (*)(char *ptr, size_t size, size_t count, void *userdata))([](char *ptr, size_t size, size_t count, void *userdata) -> size_t { - Request *req = (Request *)userdata; - auto actual_size = size * count; - req->response_body.append(ptr, actual_size); - return actual_size; - })); // curl_easy_setopt does something really ugly with parameters; I have to cast the lambda explicitly to the right kind of function pointer for some reason + curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, Request::WriteDataHandler); } pthread_mutex_lock(&rm_mutex); diff --git a/src/client/http/Request.h b/src/client/http/Request.h index e7bf34130..a6ba6a2d8 100644 --- a/src/client/http/Request.h +++ b/src/client/http/Request.h @@ -2,8 +2,11 @@ #define REQUEST_H #include +#include "common/tpt-minmax.h" // for MSVC, ensures windows.h doesn't cause compile errors by defining min/max +#include "common/tpt-thread.h" #include #include "common/String.h" +#undef GetUserName // pthreads (included by curl) defines this, breaks stuff namespace http { @@ -30,6 +33,8 @@ namespace http pthread_cond_t done_cv; + static size_t WriteDataHandler(char * ptr, size_t size, size_t count, void * userdata); + public: Request(ByteString uri); virtual ~Request(); diff --git a/src/client/http/RequestManager.h b/src/client/http/RequestManager.h index f48f39b18..222778243 100644 --- a/src/client/http/RequestManager.h +++ b/src/client/http/RequestManager.h @@ -1,12 +1,14 @@ #ifndef REQUESTMANAGER_H #define REQUESTMANAGER_H +#include "common/tpt-minmax.h" // for MSVC, ensures windows.h doesn't cause compile errors by defining min/max #include "common/tpt-thread.h" #include #include #include #include "common/Singleton.h" #include "common/String.h" +#undef GetUserName // pthreads (included by curl) defines this, breaks stuff namespace http {