您的位置:首页 > 其它

curl使用curl_easy_perform导致线程或者进程卡死解决办法

2016-11-21 10:35 615 查看
描述:curl提供的curl_easy_perform调用方式是阻塞的,如果没有收到回复,则会导致线程或者进程一直阻塞,除非外界干预。

解决办法:curl提供了CURLOPT_LOW_SPEED_LIMIT  CURLOPT_LOW_SPEED_TIME  option,主要思想为:如果在指定时间传输速率超过设置的最低值,

                    则会自动断开该链接。

举例:

                  curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT , 50);

          curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME , 5);

                  res = curl_easy_perform(curl);

官方文档解释:

CURLOPT_LOW_SPEED_TIME - set low speed limit time period

CURLOPT_LOW_SPEED_LIMIT - set low speed limit in bytes per second

CURLOPT_LOW_SPEED_TIME  Pass a long as parameter. It contains the time in number seconds that the transfer
speed should be below theCURLOPT_LOW_SPEED_LIMIT for
the library to consider it too slow and abort.

具体可以参考curl官方文档:

 https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
对于curl没有特别深入的学习,如果有更好的办法或者上面描述有误,请留言指正,谢谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  curl 线程
相关文章推荐