Skip to content
Permalink
Browse files

Fix msvc compile

  • Loading branch information...
jacob1 committed Mar 18, 2019
1 parent 296b758 commit ed2eac627bab3567167e44ff572247f1909314fa
Showing with 16 additions and 6 deletions.
  1. +9 −6 src/client/http/Request.cpp
  2. +5 −0 src/client/http/Request.h
  3. +2 −0 src/client/http/RequestManager.h
@@ -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);
@@ -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();
@@ -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
{

0 comments on commit ed2eac6

Please sign in to comment.
You can’t perform that action at this time.