Page 1 of 1
about curl functions curl_global_init / curl_easy_reset
Posted: Wed Oct 13, 2021 8:34 pm
by jparada
Hi,
I have doubt when we use curl, for example, two independent functions one from the other, in each of the functions I must use curl_global_init, and another doubt, in some examples I have seen that at the end of the function they use curl_easy_reset( curl ), but in many other examples I see that this call is not used, what is the difference between using it or not, what is recommended, it depends on some other "special" call, what is the difference?.
I appreciate your help.
Regards,
Javier
Re: about curl functions curl_global_init / curl_easy_reset
Posted: Wed Oct 13, 2021 11:08 pm
by danielmaximiliano
Re: about curl functions curl_global_init / curl_easy_reset
Posted: Thu Oct 14, 2021 9:49 am
by vagblad
Hi Javier,
curl_global_init() must be called at least once in your program, to setup the environment for the curl library to be used.
curl_easy_init() returns a handle number which you use whenever you call another curl function in order to identify for which specific curl handle you want. You can have multiple curl_easy_init() in your program for different procedures. For example:
Code: Select all
nCurlHandle_1 := curl_easy_init()
curl_easy_setopt( nCurlHandle_1, HB_CURLOPT_HTTPPOST, .T. ) //Setup this handle only for POST method so you dont have to change the curl_options for it everytime.
nCurlHandle_2 := curl_easy_init()
curl_easy_setopt( nCurlHandle_2, HB_CURLOPT_HTTPGET, .T. ) //Setup this handle only for GET method so you dont have to change the curl_options for it everytime.
or you can call multiple curl_easy_ini() and run each handle in a different thread. just be careful to call the curl_global_init() in the main thread because its not a thread safe function.
curl_easy_reset(CURL Handle) resets all the options(curl_easy_opt) for the specific handle to their default values.
For example in the above code:
Code: Select all
curl_easy_reset(nCurlHandle_1) //this will reset all the setup options for the nCurlHandle_1. so the curl_easy_setopt( nCurlHandle_1, HB_CURLOPT_HTTPPOST, .T. ) is no longer valid.
you can call curl_easy_reset() to reset the options for a specific handle and then re-setup another set of options for it while maintaining the current connection status, cache etc.