curl-library
name resolve timeout not work when multi perform with c-ares
Date: Tue, 30 Mar 2010 16:45:50 +0800 (CST)
name resolve timeout not work when multi perform with c-ares
The version of curl is 7.20.0, c-ares is 1.7.1
I must use multi perform, beacuse there is a lot of web page to get. But the CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT can't work. (when I use easy handle timeout can work right )
I don't know how to solve it , please help me. Thanks you!!
My code is :
#include<iostream>
#include<string>
#include<curl/curl.h>
using namespace std;
int main()
{
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl1 = curl_easy_init();
if (!curl1)
return 0;
curl_easy_setopt(curl1, CURLOPT_URL, "http://www.hcida.com/");
curl_easy_setopt(curl1, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(curl1, CURLOPT_CONNECTTIMEOUT, 3);
CURLM* curlm = curl_multi_init();
curl_multi_add_handle(curlm, curl1);
int running = 0;
while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curlm, &running))
{
;
}
while (running)
{
timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
int max_fd;
fd_set fd_read;
fd_set fd_write;
fd_set fd_except;
FD_ZERO(&fd_read);
FD_ZERO(&fd_write);
FD_ZERO(&fd_except);
curl_multi_fdset(curlm, &fd_read, &fd_write, &fd_except, &max_fd);
int return_code = select(max_fd + 1, &fd_read, &fd_write, &fd_except,
&tv);
if (return_code < 0)
{
break;
}
else
{
while(CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curlm,
&running))
{
;
}
}
}
curl_multi_remove_handle(curlm, curl1);
curl_easy_cleanup(curl1);
curl_multi_cleanup(curlm);
curl_global_cleanup();
return 0;
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-03-30