Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

curl_easy_init 每次http访问都需要新创建吗?

curl_easy_init在每次HTTP访问时都需要新创建吗?
使用同一个curl可以吗?
在使用同一个curl*时出现crash,逻辑如下:
init:

    _curl = curl_easy_init();
    if (!_curl) return SER_CURL_INIT_FAIL;

    curl_easy_setopt(_curl, CURLOPT_NOSIGNAL, 1L);
    curl_easy_setopt(_curl, CURLOPT_TIMEOUT, SEC_MGR_AGT_CURL_REQ_TIMEOUT);

    curl_easy_setopt(_curl, CURLOPT_HEADERFUNCTION, s_on_web_write_header);
    curl_easy_setopt(_curl, CURLOPT_HEADERDATA, this);

    curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, s_on_web_write_data);
    curl_easy_setopt(_curl, CURLOPT_WRITEDATA, this);

    curl_easy_setopt(_curl, CURLOPT_FOLLOWLOCATION, 1L);

以上为初始化,只调用一次
HTTP访问,会重复调用:

CURLcode curl_ret = curl_easy_setopt(_curl, CURLOPT_URL, url.c_str());
curl_ret = curl_easy_perform(_curl); // 在这里crash了
curl_ret = curl_easy_getinfo(_curl, CURLINFO_RESPONSE_CODE, &_http_resp_code);

堆栈:
Program terminated with signal SIGSEGV, Segmentation fault.

0 0x00000000004a3420 in Curl_strncasecompare ()

Missing separate debuginfos, use: debuginfo-install glibc-2.26-32.amzn2.0.2.x86_64 libgcc-7.3.1-6.amzn2.0.4.x86_64 libstdc++-7.3.1-6.amzn2.0.4.x86_64
(gdb) bt

0 0x00000000004a3420 in Curl_strncasecompare ()

1 0x00000000004a10b6 in Curl_checkheaders ()

2 0x0000000000494d80 in Curl_http ()

3 0x000000000047dd36 in multi_runsingle ()

4 0x000000000047e8c3 in curl_multi_perform ()

5 0x00000000004791c1 in curl_easy_perform ()

请问有什么问题?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你好,我最近也遇到这个crash的问题,用法也是初始化一次 curl句柄,想要作为长连接重复使用,调试的时候*first指针地址不正确导致crash,请问你有解决方案了吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...