gpt4 book ai didi

c++ - 使用 libcurl 多接口(interface)连续请求相同的 "easy"句柄

转载 作者:太空狗 更新时间:2023-10-29 22:54:41 26 4
gpt4 key购买 nike

我的开发组织有自己的线程和 select() 包装器实现。该应用程序需要增强以执行 HTTPS 请求,我决定使用 libcurl。经过一些研究,我发现 curl_easy_perform 是一个阻塞调用,所以我决定使用 curl_multi_perform 方法进行非阻塞调用,以允许线程中的其他工作。

需要定期对同一网址执行 HTTPS 请求。我知道我可以保留相同的 curl_easy 句柄并将其提供给 curl_multi 句柄。我会执行 curl_multi_perform 以获得结果,但我稍后需要使用 curl_multi_perform 重新发送请求,比如在 5 分钟内。 因此,这将是使用相同易处理句柄的连续请求。但是,我不确定在收到第一个请求的结果后,curl_easy 接口(interface)如何告诉多接口(interface)何时重新发送请求。我该如何做到这一点?

(也许从 multi handle 中删除 easy handle,并在再次需要请求时将其重新添加到 multi handle 中?)

我假设无论使用何种技术,传出请求都将使用相同的传出端口。

最佳答案

(Maybe drop the easy handle from the multi handle, and re-add it to the multi handle when a request is needed again?)

正确。来自 libcurl documentation :

When a single transfer is completed, the easy handle is still left added to the multi stack. You need to first remove the easy handle with curl_multi_remove_handle and then close it with curl_easy_cleanup, or possibly set new options to it and add it again with curl_multi_add_handle to start another transfer.

.

I presume that whatever technique is used, that the outgoing request will be using the same outgoing port

这不能保证。 libcurl 将尝试重新使用与 easy handle 关联的现有连接,但如果先前的连接已经终止,则将建立一个具有不可预测的本地端口的新连接。

关于c++ - 使用 libcurl 多接口(interface)连续请求相同的 "easy"句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54483937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com