Logan
Logan

Reputation: 194

Is cURL CURLOPT_WRITEFUNCTION called from same thread?

Is function specified to cURL via CURLOPT_WRITEFUNCTION called from same thread which called curl_easy_perform()?

void read_http()
{
    curl_easy_setopt(CURLOPT_WRITEFUNCTION, on_write_data);
    curl_easy_perform(hcurl);
}

the callback is like

void on_write_data(buff, ...)
{
    copy_to(buff, shared_buff);
}

client code looks like

read_http();
// use shared_buff

question is when read_http() returns has all http data been read? or could it be still in progress?

Upvotes: 3

Views: 1136

Answers (1)

Daniel Stenberg
Daniel Stenberg

Reputation: 58114

Yes it is. For all practical purposes libcurl is single-threaded and will never do callbacks from any other thread than the one you call it in.

The only other thread libcurl will ever use (if built that way) is a separate thread for name resolves, but that thread will never do any callbacks or otherwise become visible to the caller or API.

Upvotes: 4

Related Questions