Closed cryi closed 3 years ago
This is not a solution for #121 There the main problem that host application init libcurl by itself and then run Lua code. So in this case Lua should not init curl at all.
Are you sure @moteus? Setting it from lua is just optional. As long as LCURL_NO_INIT
is specified - check here. Lua wont initialize libcurl on its own.
I just added option to initialize it from lua manually on top of your requirement to disable initialization.
Sorry. You are right. I have only one (very small) concern. getenv is not thread safe function. But I do not see a better way to handle this rather than just ignoring this.
Well curl_global_init is not thread safe on its own. So in context of loading lcurl there should not be difference after merging.
getenv
thread safety is mostly about the validity of pointer it returns (it may invalidated over time in multi threaded setup) but we do not care for its validity - we do not read anything from it.
NULL value is our only concern here and only potential issue I can see, would be if someone tries to set LCURL_NO_INIT
from background thread while loading lcurl on main or vice versa. We can mention that in docs.
But I believe that devs working in multithreaded lua realize that initialization has to be done before everything else and as such setting LCURL_NO_INIT
has to be done before spawning multiple threads of lcurl or lua states containing lcurl.
Hi,
I tried to resolve #121. Everything works as before and I verified that library is not initialized if LCURL_NO_INIT set. Manual initialization is possible with init function on both lcurl and lcurl.safe. Although I am not sure whether expose CURL_GLOBAL_DEFAULT and others directly on lcurl and lcurls.safe, so for now initialization mode has to be passed as number.
Although I am not able to verify custom initialization. I use only easy methods and easy calls curl_global_init on its own in case it was not initialized before. It would be great if you can test in more suitable scenario.
Fixes #121.