Libcurl Hostname was NOT found in DNS cache

≡放荡痞女 提交于 2019-12-11 03:15:41

问题


I'm trying 2 parallel connection with curl_multi :

CURL *http_handle;
CURL *http_handle2;
CURLM *multi_handle;

int still_running; /* keep number of running handles */

http_handle = curl_easy_init();
http_handle2 = curl_easy_init();

/* set options */
curl_easy_setopt(http_handle, CURLOPT_URL, "http://216.58.208.46");

/* set options */
curl_easy_setopt(http_handle2, CURLOPT_URL, "http://213.180.204.62");

curl_easy_setopt(http_handle, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(http_handle2, CURLOPT_VERBOSE, 1L);

/* init a multi stack */
multi_handle = curl_multi_init();

/* add the individual transfers */
curl_multi_add_handle(multi_handle, http_handle);
curl_multi_add_handle(multi_handle, http_handle2);

/* we start some action by calling perform right away */
curl_multi_perform(multi_handle, &still_running);

while(still_running);

curl_multi_cleanup(multi_handle);

curl_easy_cleanup(http_handle);
curl_easy_cleanup(http_handle2);

return 0;

and get console output:

  • Rebuilt URL to: http://216.58.208.46/
  • Hostname was NOT found in DNS cache
  • Trying 216.58.208.46...
  • Rebuilt URL to: http://213.180.204.62/
  • Hostname was NOT found in DNS cache
  • Trying 213.180.204.62...

everything works perfectly if i use curl_easy_perform but i not with curl_multi_perform so is there a bug in libcurl or I'm doing something wrong ? my libcurl version is 7.37.1


回答1:


You seem to have misunderstood how curl_multi_perform works. It only does a very small piece of the transfer and then returns, and you need to keep calling it until all the transfers are done. (Not in a busy-loop, you should also wait for "action" before you call it again.)

An example code showing two parallel transfers done with the multi interface is the multi-double example on the curl web site.

The texts about not found in the DNS cache is just junk and is removed in a future version, and the "rebuild" text just informs you how libcurl fixed the URL for you automatically and that it uses that fixed version going forward. The "Trying" part is libcurl starting the connect to the hosts but since you never call it again, it can't finish its job!



来源:https://stackoverflow.com/questions/28065002/libcurl-hostname-was-not-found-in-dns-cache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!