我查了查curl的网站,说是curl_global_init是thread unsafe的,是不是不该这样调用curl_global_init,而应该在线程start之前?我试了试,放了几个地方都不行,虽然没有非正常退出,但是抛出未知异常,执行不到调用curl_easy_perform( )函数的地方了。
大牛们给点意见?谢谢!
--
孤舘燈青
野店雞號
旅枕夢殘
[m [37m※ 来源:·水木社区 http://newsmth.net·[FROM: 147.243.236.*] [m
【 在 UN733 (阿水) 的大作中提到: 】
: 接手别人的一个程序,用了curl库。在调用curl_easy_perform( )函数后程序非正常退出,coredump了。
: 程序是多线程的,在每个线程里的curl_easy_perform( )函数调用之前,都有这两个调用:
: curl_global_init(CURL_GLOBAL_ALL);
: ...................
--
[m [1;34m※ 来源:·水木社区 newsmth.net·[FROM: 219.143.222.*] [m
--
[m [1;32m※ 来源:·水木社区 newsmth.net·[FROM: 60.247.104.*] [m
struct memoryStruct response;
response.memory=NULL;
response.size = 0;
curl_global_init(CURL_GLOBAL_ALL);
CURL *c = curl_easy_init();
if( ! c ) {
CPFDEF::Error_c err(SLCCOR_CURL_INIT_EXCEPTION,
"Error during curl initialisation");
err.SetLocation(__FILE__, __LINE__);
CPFCEC::ErrorLog_c::Send( err );
}
int curlErrFlag = 0;
if (( curl_easy_setopt(c, CURLOPT_URL, url)) != CURLE_OK ) curlErrFlag = 1;
//...a lot of curl_easy_setopt calling
if (( curl_easy_setopt(c, CURLOPT_SSL_VERIFYHOST, 0))!= CURLE_OK ) curlErrFlag = 1;
trace << " curlErrFlag = " << curlErrFlag << endl << flush ;
if ( curlErrFlag == 1 )
{
result = SLCCOR_CURL_ERROR;
}
else
{
CURLcode resultCode = curl_easy_perform( c );
trace << " resultCode = " << resultCode << endl << flush ;
if ( resultCode == CURLE_COULDNT_CONNECT || resultCode == CURLE_COULDNT_RESOLVE_HOST )
{
result = SLCCOR_NO_NE_CONNECT ;
}
if(response.memory)
{
xmlResponse = response.memory;
}
free (response.memory);
curl_easy_cleanup( c );
}
}
catch (...) {
//...
}
}
【 在 shellcode (从头再来) 的大作中提到: 】
: 贴问题代码吧
See the description in libcurl(3) of global environment requirements
for details of how to use this function.
是不是这个函数只用在主线程里调一次?
【 在 UN733 (阿水) 的大作中提到: 】
: 下面是线程函数体。
: 去掉了一些无关的东西,大体结构是这样的。trace文件里有curlErrFlag = 0, 但是没有resultCode = 的信息,说明是curl_easy_perform( )出的错。而且负责通信的另一端的人说,命令是传送过去并执行了的。
: 大牛们看看?
是不是应该在主线程里调用curl_global_init呢?
【 在 UN733 (阿水) 的大作中提到: 】
: 在http://curl.haxx.se/libcurl/c/curl_easy_init.html 看到的:
: If you did not already call curl_global_init(3), curl_easy_init(3) does it automatically. This may be lethal in multi-threaded cases, since curl_global_init(3) is not thread-safe, and it may result in resource problems because there is no correspondi
: 估计是不行吧,因为我们的东西是多线程的。我试试看。
--
孤舘燈青
野店雞號
旅枕夢殘
[m [32m※ 来源:·水木社区 http://newsmth.net·[FROM: 147.243.236.*] [m
execsh=mmi&cliLines=%3c%3fxml version=%221%2e0%22%3f%3e%3cCLIREQUEST Version=%221%2e0%22%3e%3cTRANSACTION Number=%221%22%3e%3 ivateimsi n112233445588888%3ar7508%3as0%3a1%3c%2fCMDTEXT%3e%3c%2fCMDREQUEST%3e%3c%2fTRANSACTION%3e%3c%2fCLIREQUEST%3e< HTTP/1
< Date: Thu, 05 Jun 2008 10:15:16 GMT
< Server: Apache/1.3.6 (Unix) mod_auth_pam/1.1.1 mod_ssl/2.3.11 OpenSSL/0.9.7d
< Transfer-Encoding: chunked
< Content-Type: text/html
* Connection #0 to host 10.8.15.58 left intact
* Closing connection #0
*** glibc detected *** double free or corruption (fasttop): 0x084fa4a8 ***
【 在 UN733 (阿水) 的大作中提到: 】
: 接手别人的一个程序,用了curl库。在调用curl_easy_perform( )函数后程序非正常退出,coredump了。
: 程序是多线程的,在每个线程里的curl_easy_perform( )函数调用之前,都有这两个调用:
: curl_global_init(CURL_GLOBAL_ALL);
: ...................
--
孤舘燈青
野店雞號
旅枕夢殘
[m [33m※ 来源:·水木社区 http://newsmth.net·[FROM: 125.70.82.*] [m