LibCurl WriteCallback (Async?) - C++

Viewed 5211

I am successfully making an http POST call using the following code:

std::string curlString;
CURL* pCurl = curl_easy_init();

if(!pCurl)
    return NULL;

string outgoingUrl = Url;
string postFields = fields;

curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, 0);

curl_easy_setopt(pCurl, CURLOPT_URL, outgoingUrl.c_str());
curl_easy_setopt(pCurl, CURLOPT_POST, 1);

curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, postFields.c_str());
curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE, (long)postFields.size());

curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &curlString);

curl_easy_perform(pCurl);

curl_easy_cleanup(pCurl);

The write callback has the following prototype:

size_t CurlWriteCallback(char* a_ptr, size_t a_size, size_t a_nmemb, void* a_userp);

Is there a way to do this asynchronously? Currently it waits for the callback to finish before curl_easy_perform returns. This blocking method won't work for a server with many users.

1 Answers
Related