Fix msvc compile

This commit is contained in:
jacob1 2019-03-17 21:18:55 -04:00
parent 296b758193
commit ed2eac627b
3 changed files with 16 additions and 6 deletions

View File

@ -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);

View File

@ -2,8 +2,11 @@
#define REQUEST_H
#include <map>
#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 <curl/curl.h>
#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();

View File

@ -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 <ctime>
#include <set>
#include <curl/curl.h>
#include "common/Singleton.h"
#include "common/String.h"
#undef GetUserName // pthreads (included by curl) defines this, breaks stuff
namespace http
{