Skip to content

Commit

Permalink
Fix msvc compile
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Mar 19, 2019
1 parent 296b758 commit ed2eac6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/client/http/Request.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/client/http/Request.h
Expand Up @@ -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
{
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions 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 <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
{
Expand Down

0 comments on commit ed2eac6

Please sign in to comment.