c++ - 在 DNS 缓存中未找到 Libcurl 主机名

标签 c++ libcurl

我正在尝试使用curl_multi进行2个并行连接:

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;

并获取控制台输出:

如果我使用curl_easy_perform但我不使用curl_multi_perform,一切都会完美运行,那么libcurl中是否存在错误或者我做错了什么?我的 libcurl 版本是 7.37.1

最佳答案

你似乎误解了 curl_multi_perform作品。它只执行一小部分传输然后返回,您需要不断调用它直到所有传输完成。 (不在繁忙循环中,您还应该在再次调用它之前等待“action”。)

显示使用多接口(interface)完成的两个并行传输的示例代码是 multi-double curl 网站上的示例。

有关在 DNS 缓存中找不到的文本只是垃圾,将在未来版本中删除,而“重建”文本只是告诉您 libcurl 如何自动为您修复 URL,并且它会在以后使用该固定版本。 “尝试”部分是 libcurl 启动与主机的连接,但由于您再也没有调用它,因此它无法完成其工作!

关于c++ - 在 DNS 缓存中未找到 Libcurl 主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28065002/

相关文章:

c++ - WNDCLASSEX 和 CreateWindow 有什么区别?

C++ 设计 : functions with boolean options

c++ - 对类方法进行指针部分特化时获取 "illegal use of explicit template arguments"

C++:如何通过 curl 调用使用 HTTP post 请求发送二进制数据(protobuf 数据)

c++ - Curl 和 Macosx 10.12

c++ - Armadillo C++ : Efficient and concise way to multiply every row of a matrix by a vector?

两个大数组之间的 C++ 归一化互相关

ios - Xcode5 上的 libcurl 链接器错误,但在 Xcode 4.6 上工作正常

执行结束时的c++段错误

c++ - 如何在 C++ 中使用文件指针 CURL POST 文件