Buy commercial curl support from WolfSSL. We help you work
out your issues, debug your libcurl applications, use the API, port to new
platforms, add new features and more. With a team lead by the curl founder
himself.
Using libcurl in another library, when/if to call curl_global_init?
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Mark Wielaard via curl-library <curl-library_at_lists.haxx.se>
Date: Thu, 31 Mar 2022 14:04:15 +0200
Hi,
We we are using libcurl in our own library now to (optionally) fetch
resources from http(s) locations. It is an implementation detail we use
libcurl for this and don't expose any Curl handles outside our own
library. It works great, thanks!
But we are struggling a bit with how to safely/correctly initialize
libcurl. Our own library doesn't need any global initialization, so
users won't use any global init like function. We have therefore added
a constructor function to the library that is called as soon as the
library is loaded which simply calls
curl_global_init(CURL_GLOBAL_DEFAULT);
We added it in the constructor so that it is called as early as
possible (hopefully) before the program created any threads because the
curl_global_init documentation says to call it before any threads are
created by the program.
This seems to work, but it means that curl_global_init is always called
even if our own library happens to not use libcurl to fetch any remote
resources. And this is causing some problems for our users because (in
FIPS mode) libcurl does significant initialization work (to check the
ssl implementation?)
The documentation seems to imply that you can also call curl_easy_init
without calling curl_global_init first. And doing that seems to work
fine. But our own testsuite doesn't contain many multi-threaded
examples.
Since the documentation does imply that doing without curl_global_init
might not be thread-safe we wonder how other libraries that use libcurl
are doing this. Or whether there is a thread-safe way to call
curl_global_init at a later time (to get rid of the library constructor
init function).
Thanks,
Mark
Date: Thu, 31 Mar 2022 14:04:15 +0200
Hi,
We we are using libcurl in our own library now to (optionally) fetch
resources from http(s) locations. It is an implementation detail we use
libcurl for this and don't expose any Curl handles outside our own
library. It works great, thanks!
But we are struggling a bit with how to safely/correctly initialize
libcurl. Our own library doesn't need any global initialization, so
users won't use any global init like function. We have therefore added
a constructor function to the library that is called as soon as the
library is loaded which simply calls
curl_global_init(CURL_GLOBAL_DEFAULT);
We added it in the constructor so that it is called as early as
possible (hopefully) before the program created any threads because the
curl_global_init documentation says to call it before any threads are
created by the program.
This seems to work, but it means that curl_global_init is always called
even if our own library happens to not use libcurl to fetch any remote
resources. And this is causing some problems for our users because (in
FIPS mode) libcurl does significant initialization work (to check the
ssl implementation?)
The documentation seems to imply that you can also call curl_easy_init
without calling curl_global_init first. And doing that seems to work
fine. But our own testsuite doesn't contain many multi-threaded
examples.
Since the documentation does imply that doing without curl_global_init
might not be thread-safe we wonder how other libraries that use libcurl
are doing this. Or whether there is a thread-safe way to call
curl_global_init at a later time (to get rid of the library constructor
init function).
Thanks,
Mark
-- Unsubscribe: https://lists.haxx.se/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.htmlReceived on 2022-03-31