cURL / Mailing Lists / curl-library / Single Mail

curl-library

Can I Use CURLOPT_DNS_CACHE_TIMEOUT and CURL_LOCK_DATA_DNS at the same time£¿

From: yeguo wu <wuyeguo_at_gmail.com>
Date: Wed, 30 Aug 2006 10:58:32 +0800

Hi All£º
    I want to start 200 threads to download pages use Libcurl.Who can tell
me how to set the DNS Cache Timeout in the CURLOPT_SHARE,
Can I watch if the DNS Cache is working?? Thank you.
my program is as follows£º

int m_init(){
 int ret;
 CURLSHcode shareError;
 ret = 0;

 curl_global_init(CURL_GLOBAL_ALL);
 share = curl_share_init();

 shareError = curl_share_setopt( share, CURLSHOPT_LOCKFUNC, m_lock);
 if(shareError){
  cerr<<"share set opt wrong"<<endl;
  curl_share_cleanup(share);
  ret = 1;
 }
 shareError = curl_share_setopt( share, CURLSHOPT_UNLOCKFUNC, m_unlock);
 if(shareError){
  cerr<<"share set opt wrong"<<endl;
  curl_share_cleanup(share);
  ret = 1;
 }
 shareError = curl_share_setopt( share, CURLSHOPT_USERDATA, &locker);
 if(shareError){
  cerr<<"share set opt wrong"<<endl;
  curl_share_cleanup(share);
  ret = 1;
 }
 shareError = curl_share_setopt(share,CURLSHOPT_SHARE,CURL_LOCK_DATA_DNS);
 if(shareError){
  cerr<<"share set opt wrong"<<endl;
  curl_share_cleanup(share);
  ret = 1;
 }
 return ret;
}

int curl_httpget(const char* URLbuf, std::string *chunk, int DNStimeout,
long *res_code, char *errorBuffer)
{
 CURL *curl_handle;
 int errcode=0;

 /* init the curl session */
 curl_handle = curl_easy_init();
 curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errorBuffer);
 curl_easy_setopt(curl_handle, CURLOPT_URL, URLbuf);
 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 0);
 curl_easy_setopt(curl_handle, CURLOPT_DNS_USE_GLOBAL_CACHE, 0);
 curl_easy_setopt(curl_handle, CURLOPT_DNS_CACHE_TIMEOUT, DNStimeout);
 curl_easy_setopt(curl_handle,CURLOPT_SHARE,share);
 /* send all data to this function */
 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
 /* we pass our 'chunk' struct to the callback function */
 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)chunk);
 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.1)");
 /* get it! */
 errcode=curl_easy_perform(curl_handle);
 curl_easy_getinfo(curl_handle,CURLINFO_RESPONSE_CODE,res_code);
 /* cleanup curl stuff */
 curl_easy_cleanup(curl_handle);
 return errcode;
}
Received on 2006-08-30