卷曲未正确超时
Curl not timing out properly
本文关键字:超时 更新时间:2023-10-16
我设置了CURLOPT_CONNECTTIMEOUT_MS = 200和CURLOPT_TIMEOUT_MS = 70 ms。但我看到CURLINFO_TOTAL_TIME在 220 毫秒左右。
根据 libcurl 文档,CURLOPT_TIMEOUT_MS还包括连接超时。所以基本上我的 curl 调用总时间不应该超过 70 毫秒。但是,为什么要收回更多的控制权呢?
有人可以解释一下这种行为吗?
我正在使用 curl 7.19_02 C++库。
这是我的代码
CURL * curl;
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT_MS,200);
curl_easy_setopt(curl,CURLOPT_TIMEOUT_MS,70);
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
double tt = 0.0;
double ns = 0.0;
double ct = 0.0;
double pt = 0.0;
double st = 0.0;
curl_easy_perform(curl);
int curlRC = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &tt);
curlRC = curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &ns);
curlRC = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &ct);
curlRC = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pt);
curlRC = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &st);
cout << "Curl timing info: Total: " << tt << endl << " Lookup: "<< ns << endl << " Connect: " << ct << "n" << "pre transfer: " << pt << endl << "start transfer: " << st <<endl;
我得到的时间信息如下。请检查一下
卷曲计时信息: 总计:0.216793
查找: 0.000999
连接: 0.023199
预转移:0.023213
开始传输:0.216667
所以关键是,预转移和开始转移之间发生了什么?
这是 libcurl 到 7.20.0 版本的错误。在 7.20.1 中,输出与预期一致:
Curl timing info: Total: 0.071098
Lookup: 0.000116
Connect: 0.000303
pre transfer: 0.000327
start transfer: 0
我找不到修复该错误的变更集。但可能是在 cURL 更改中的"亚秒级超时改进"<</p>
所以关键是,预转移和开始转移之间发生了什么?
这是服务器计算结果(处理请求)并准备好发送响应的第一个字节所花费的实际时间。简而言之,这是请求的实际服务器时间,您会期望这是最大的部分
相关文章:
- C++减少modbus_connect超时
- 没有超时的C++条件变量
- 如何在C++(VS2010)中设置超时读取USB端口?
- C++卷曲柱在curl_easy_perform超时
- 如何在Qt 4.8中阻止/忽略/丢弃早于特定超时的用户输入事件
- 如何改进我的代码,使其不会因超时而终止?(黑客排名挑战)
- C++:函数外部的超时功能
- 使用boost::multiprecision cpp_int左移时出现超时错误
- QTimer 超时不会在单元测试中触发
- 使用单体计时器的pthread_cond_timedwait有时会比预期晚超时
- 超时后,线程睡眠不会继续执行
- 接受超时的 TCP 连接
- 为 g++ build 设置超时,为 Sublime Text 运行?
- 如何通过命令行工具在 COIN-OR Cbc 中设置超时?
- 高CPU使用率,在API桌面复制中获取帧之间具有不同的超时间隔
- 0作为std::condition_variable::wait_fo中的超时
- 为什么我在蓝牙连接()上收到"java.io.IOException:读取失败,套接字可能关闭或超时,读取re
- UDP 套接字 select() 在某些情况下无延迟(超时)返回 1
- 使用 alarm() 实现进程超时
- 设置 c/c++ 函数调用的超时