Tahseen
Tahseen

Reputation: 87

libcurl call back functions, using the easy interface

I am trying to understand/make sure about the nature of "callback function" utilized by libcurl. As usual, after setting all the options using curl_easy_setopt, I would call curl_easy_perform.

But when there is a call back function will libcurl actually return absolutely all the data before exiting curl_easy_perform.

I understand that the multi-interface is there to provide non-blocking capabilities. But "call back functions" are meant to be called "later in time" while other stuff is taking place, right? So for easy-interface is it really blocking till all data is received? How can I test this?

I have been researching and I put below two quotes from the libcurl docs. But I am stuck at trying to comprehend the concepts of call back functions and blocking manner http://curl.haxx.se/libcurl/c/curl_easy_perform.html

curl_easy_perform - man page:

curl_easy_perform performs the entire request in a blocking manner and returns when done, or if it failed. For non-blocking behavior, see curl_multi_perform.”

http://curl.haxx.se/libcurl/c/curl_multi_perform.html

curl_multi_perform - man page:

This function handles transfers on all the added handles that need attention in an non-blocking fashion”

Please note that the aim is to make sure that after the end of my function call, the application must have ALL the data. We are doing things strictly sequentially and can not afford chunks of data flying in at different times.

Upvotes: 0

Views: 1251

Answers (1)

Daniel Stenberg
Daniel Stenberg

Reputation: 58004

Yes, the easy interface is blocking until the entire request is complete. You can test this by doing lots of requests and verifying that it works this way - or just trust the docs and the thousands of users who depend on this behavior.

"Callbacks" means that they are functions you write and provide that get "called back" from the function you invoke. So, you call curl_easy_perform() and then libcurl itself calls back to your callback function(s) according to the documentation all the way until either something failed or the transfer is complete and then curl_easy_perform() returns back to your program again.

Upvotes: 1

Related Questions