Skip to content

Commit

Permalink
asyncpp_uv_curl: CurlSession moved to object file and renamed to Curl…
Browse files Browse the repository at this point in the history
…PrivateSession
  • Loading branch information
KrystianD committed Feb 3, 2022
1 parent 9877c5f commit a5ac294
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 1 addition & 11 deletions modules/asyncpp_uv_curl/include/asyncpp_uv_curl/curl_uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <string>
#include <utility>
#include <chrono>
#include <memory>

namespace curl_uv {
struct CurlSession;

enum class Method {
GET,
Expand Down Expand Up @@ -76,16 +76,6 @@ class CurlResponse {

typedef std::function<void(CurlResponse&& response)> CurlCompletedCb;

struct CurlSession {
CURL* handle;
char errorBuffer[CURL_ERROR_SIZE];

CurlRequest request;
CurlResponse response;

CurlCompletedCb completedCb;
};

CurlRequest get(const std::string& url);
CurlRequest post(const std::string& url);
CurlRequest delete_(const std::string& url);
Expand Down
24 changes: 18 additions & 6 deletions modules/asyncpp_uv_curl/src/curl_uv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@
#include <sstream>

namespace curl_uv {
struct CurlPrivateSession;

CURLM* curlMultiHandle;
uv_timer_t uvTimeout;

void fillResponse(CurlSession* session, CURLcode result);
void fillResponse(CurlPrivateSession* session, CURLcode result);

struct CurlPrivateSession {
CURL* handle;
char errorBuffer[CURL_ERROR_SIZE];

CurlRequest request;
CurlResponse response;

CurlCompletedCb completedCb;
};

typedef struct curl_context_s {
uv_poll_t poll_handle;
Expand Down Expand Up @@ -54,7 +66,7 @@ static void curl_checkMultiInfo() {
returned pointer points to will not survive calling
curl_multi_cleanup, curl_multi_remove_handle or
curl_easy_cleanup." */
CurlSession* session;
CurlPrivateSession* session;
curl_easy_getinfo(message->easy_handle, CURLINFO_PRIVATE, &session);

CURLcode result = message->data.result;
Expand Down Expand Up @@ -138,7 +150,7 @@ static int curl_handleSocket(CURL* easy [[maybe_unused]], curl_socket_t s, int a
}

static size_t curl_writeFunction(void* data, size_t size, size_t nmemb, void* userp) {
CurlSession* session = (CurlSession*)userp;
CurlPrivateSession* session = (CurlPrivateSession*)userp;

size_t realsize = size * nmemb;

Expand Down Expand Up @@ -185,7 +197,7 @@ void fillRequest(CURL* curl, const CurlRequest& request) {
}
}

void fillResponse(CurlSession* session, CURLcode result) {
void fillResponse(CurlPrivateSession* session, CURLcode result) {
long statusCode = 0;
curl_easy_getinfo(session->handle, CURLINFO_RESPONSE_CODE, &statusCode);

Expand All @@ -196,7 +208,7 @@ void fillResponse(CurlSession* session, CURLcode result) {
}

void execute(CurlRequest&& request, CurlCompletedCb completedCb) {
CurlSession* session = new CurlSession();
CurlPrivateSession* session = new CurlPrivateSession();

session->request = std::move(request);
session->response.buffer.reserve(1024);
Expand All @@ -219,7 +231,7 @@ void execute(CurlRequest&& request, CurlCompletedCb completedCb) {
}

CurlResponse executeSync(CurlRequest&& request) {
CurlSession* session = new CurlSession();
CurlPrivateSession* session = new CurlPrivateSession();

session->request = std::move(request);
session->response.buffer.reserve(1024);
Expand Down

0 comments on commit a5ac294

Please sign in to comment.