public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Using libcurl in another library, when/if to call curl_global_init?
@ 2022-03-31 12:04 Mark Wielaard
       [not found] ` <b424b435-482d-7d24-4337-8ef7437ab05c@mega.nz>
  2022-04-05 15:36 ` Daniel Stenberg
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Wielaard @ 2022-03-31 12:04 UTC (permalink / raw)
  To: curl-library; +Cc: elfutils-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-22 22:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31 12:04 Using libcurl in another library, when/if to call curl_global_init? Mark Wielaard
     [not found] ` <b424b435-482d-7d24-4337-8ef7437ab05c@mega.nz>
2022-03-31 13:19   ` Mark Wielaard
2022-04-05 15:24     ` Florian Weimer
2022-04-22 22:14     ` Mark Wielaard
2022-04-05 15:36 ` Daniel Stenberg
2022-04-05 16:19   ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).