gpt4 book ai didi

c - 多个可执行文件上的 libcurl 和curl_global_init()

转载 作者:行者123 更新时间:2023-11-30 16:50:20 31 4
gpt4 key购买 nike

我必须实现一个 bash 脚本,它使用 libcurl 向网络服务器循环执行 2 个请求。

该脚本具有以下结构:

while :
do
./callA
sleep(50)
./callB
sleep(10)
done

callA和callB的二进制代码具有以下结构:

#include <curl/curl.h>

int main(int argc, char *argv[]){

...

curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(various settings...);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
//do something...
}
else {
//handle error...
}
}

curl_easy_cleanup(curl);
curl_global_cleanup();

}

来自 libcurl documentation我读到:

The program must initialize some of the libcurl functionality globally. That means it should be done exactly once, no matter how many times you intend to use the library. Once for your program's entire life time. This is done using curl_global_init()

对我来说,不清楚“程序的整个生命周期”是否意味着如果我在两个单独的可执行程序中使用 libcurl,我无论如何都必须声明一次,例如在一个作为初始化程序的单独文件中。或者,我必须在 callA 源代码和 callB 中都定义。

最佳答案

在您的情况下,callAcallB是两个截然不同的程序,每个程序在一个进程中运行,因此彼此完全独立。

它们各有一个“生命周期”,因此都应该调用 curl_global_init()

关于c - 多个可执行文件上的 libcurl 和curl_global_init(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228664/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com