Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is cURL CURLOPT_WRITEFUNCTION called from same thread?

Tags:

c++

curl

libcurl

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?

like image 826
Logan Avatar asked Dec 10 '25 00:12

Logan


1 Answers

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.

like image 124
Daniel Stenberg Avatar answered Dec 12 '25 14:12

Daniel Stenberg