Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is curl_global_init() necessary at all?

Tags:

c

curl

Though its document says this function is MUST, but I saw two examples, one has it, the other doesn't.

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

http://curl.haxx.se/libcurl/c/multi-app.html

Is this function necessary at all?

like image 503
compile-fan Avatar asked May 22 '11 12:05

compile-fan


1 Answers

If it is designed it will be necessary. The documentation says:

This function must be called at least once within a program (a program is all the code that shares a memory space) before the program calls any other function in libcurl. The environment it sets up is constant for the life of the program and is the same for every program, so multiple calls have the same effect as one call.

But please note that in documentation of curl_easy_init:

If you did not already call curl_global_init(3), curl_easy_init(3) does it automatically. This may be lethal in multi-threaded cases, since curl_global_init(3) is not thread-safe, and it may result in resource problems because there is no corresponding cleanup.

like image 92
ahmet alp balkan Avatar answered Sep 22 '22 07:09

ahmet alp balkan