16

I am using curl to send POST and GET requests and I use callback functions to get the replies from these requests. These callback functions are static member functions which in turn call non static member functions (you can't use non static member functions in curl directly so therefor this workaround).

Since these callback functions can't return a result, I use an attribute in my C++ class to store the reply. This all works fine but now my question. Does curl_easy_perform() block until the entire request is sent AND the reply is processed by the callback function OR does my program continue after curl_easy_perform() and is it getting interrupted somehow when the reply from the request is received?

The importance to me is that I want to be sure that the data in my attribute that should contain the reply is already in there or is it possible that there is still old data in this attribute because the callback function hasn't yet been called.

I realize that my explanation is not very clear so if you don't understand, please let me know and I will try to rephrase it.

Thanks!

Silver
  • 1,075
  • 3
  • 12
  • 37
  • A callback will be called inside the function you pass it to. – Tony The Lion Mar 09 '13 at 14:26
  • So you mean I misuse the word callback function? I just tell curl that when data comes in it needs to pass this data on to a certain function. I thought that was also a callback function. But you pass the callback function to curl in curl_easy_setopt(). All options for the request are being set before curl_easy_perform(). I just want to know if curl_easy_perform() blocks until the request is dealt with. – Silver Mar 09 '13 at 14:50

1 Answers1

18

Does curl_easy_perform() block until the entire request is send AND the reply is processed by the callback function

Yes, that is exactly what it does.

(If you rather want a non-blocking behavior, libcurl's multi interface is the way to go.)

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
  • 1
    please have a look of my question about `curl_multi_*` interface: http://stackoverflow.com/questions/24288513/how-to-do-curl-multi-perform-asynchronously-in-c – Thanh-Nhon Nguyen Jun 18 '14 at 14:54