0

我的应用程序中的 Libcurl 似乎对不存在的域有问题,因为它在“ NXDOMAIN ”请求(这似乎与 CURLOPT_CONNECTTIMEOUT 匹配)上保持至少 7-20 秒。

这是 pmp(穷人的探查器)输出:

   2585 __GI___poll,Curl_poll,curl_multi_wait,curl_easy_perform,getweb,athread,start_thread,clone,??
   1281 __GI___poll,Curl_poll,curl_multi_wait,curl_easy_perform,getweb,getweb,athread,start_thread,clone,??
    100 nanosleep,__sleep,athread,start_thread,clone,??
    ...

curl命令似乎没有这个问题。它在一秒钟内完成相同的请求。

这个问题可能与这个有关,因为似乎我已经解决了一个问题并最终解决了另一个问题,无法判断它是在最后一次 ubuntu 更新之后还是之前。

这是我项目中的 libcurl 代码:

PAGE_TIMEOUT=20;
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, (PAGE_TIMEOUT-PAGE_TIMEOUT%3)/3); //3 times less
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 20);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, PAGE_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_URL, argv);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &header);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
dns_index=DNS_SERVER_I;
pthread_mutex_lock(&running_mutex);
    if(DNS_SERVER_I>DNS_SERVERS.size())
    {
        DNS_SERVER_I=1;
    }else
    {
        DNS_SERVER_I++;
    }
pthread_mutex_unlock(&running_mutex);
}
string dns_servers_string=DNS_SERVERS.at(dns_index%DNS_SERVERS.size())+","+DNS_SERVERS.at((dns_index+1)%DNS_SERVERS.size())+","+DNS_SERVERS.at((dns_index+2)%DNS_SERVERS.size());
curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, &dns_servers_string[0]);    
curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE,false);

struct curl_slist *slist=NULL;
slist = curl_slist_append(slist, "ACCEPT: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5");
slist = curl_slist_append(slist, "ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
slist = curl_slist_append(slist, "ACCEPT_ENCODING: gzip,deflate");
slist = curl_slist_append(slist, "ACCEPT_LANGUAGE: en-gb,en;q=0.5");
slist = curl_slist_append(slist, "CONNECTION: keep-alive");
slist = curl_slist_append(slist, "KEEP_ALIVE: 300");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
string useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16";
curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent.c_str());   

sm=curl_easy_perform(curl);

我已经从源代码构建了 libcurl v7.30(使用 c-ares 并且没有 ipv6)并安装在 ubuntu 12.10 存储库版本上(不确定是否被覆盖,我使用过make install)。

在上次自动更新后,我收到了一个错误,但不知道它是否相关。

4

0 回答 0