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 ()
请问有什么问题?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…