2002-09-03 19:52:59 +08:00
|
|
|
/***************************************************************************
|
2004-10-06 15:50:18 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
1999-12-29 22:20:26 +08:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2020-11-05 15:22:10 +08:00
|
|
|
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
1999-12-29 22:20:26 +08:00
|
|
|
*
|
2002-09-03 19:52:59 +08:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2004-10-06 15:50:18 +08:00
|
|
|
*
|
2001-01-03 17:29:33 +08:00
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
2002-09-03 19:52:59 +08:00
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
1999-12-29 22:20:26 +08:00
|
|
|
*
|
2001-01-03 17:29:33 +08:00
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
1999-12-29 22:20:26 +08:00
|
|
|
*
|
2002-09-03 19:52:59 +08:00
|
|
|
***************************************************************************/
|
1999-12-29 22:20:26 +08:00
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2000-08-24 22:26:33 +08:00
|
|
|
|
1999-12-29 22:20:26 +08:00
|
|
|
#include <curl/curl.h>
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "speedcheck.h"
|
1999-12-29 22:20:26 +08:00
|
|
|
|
2016-06-21 21:47:12 +08:00
|
|
|
void Curl_speedinit(struct Curl_easy *data)
|
2000-10-17 22:53:03 +08:00
|
|
|
{
|
2017-07-28 21:49:36 +08:00
|
|
|
memset(&data->state.keeps_speed, 0, sizeof(struct curltime));
|
2000-10-17 22:53:03 +08:00
|
|
|
}
|
|
|
|
|
2017-04-05 06:42:34 +08:00
|
|
|
/*
|
|
|
|
* @unittest: 1606
|
|
|
|
*/
|
2016-06-21 21:47:12 +08:00
|
|
|
CURLcode Curl_speedcheck(struct Curl_easy *data,
|
2017-07-28 21:49:36 +08:00
|
|
|
struct curltime now)
|
1999-12-29 22:20:26 +08:00
|
|
|
{
|
2020-12-22 16:54:06 +08:00
|
|
|
if(data->req.keepon & KEEP_RECV_PAUSE)
|
|
|
|
/* A paused transfer is not qualified for speed checks */
|
|
|
|
return CURLE_OK;
|
|
|
|
|
2017-04-05 06:42:34 +08:00
|
|
|
if((data->progress.current_speed >= 0) && data->set.low_speed_time) {
|
|
|
|
if(data->progress.current_speed < data->set.low_speed_limit) {
|
|
|
|
if(!data->state.keeps_speed.tv_sec)
|
|
|
|
/* under the limit at this very moment */
|
|
|
|
data->state.keeps_speed = now;
|
|
|
|
else {
|
|
|
|
/* how long has it been under the limit */
|
2017-10-23 18:05:49 +08:00
|
|
|
timediff_t howlong = Curl_timediff(now, data->state.keeps_speed);
|
1999-12-29 22:20:26 +08:00
|
|
|
|
2017-04-05 06:42:34 +08:00
|
|
|
if(howlong >= data->set.low_speed_time * 1000) {
|
|
|
|
/* too long */
|
|
|
|
failf(data,
|
|
|
|
"Operation too slow. "
|
|
|
|
"Less than %ld bytes/sec transferred the last %ld seconds",
|
|
|
|
data->set.low_speed_limit,
|
|
|
|
data->set.low_speed_time);
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
1999-12-29 22:20:26 +08:00
|
|
|
}
|
2017-04-05 06:42:34 +08:00
|
|
|
else
|
|
|
|
/* faster right now */
|
|
|
|
data->state.keeps_speed.tv_sec = 0;
|
1999-12-29 22:20:26 +08:00
|
|
|
}
|
2006-10-17 17:05:44 +08:00
|
|
|
|
2017-04-05 06:42:34 +08:00
|
|
|
if(data->set.low_speed_limit)
|
|
|
|
/* if low speed limit is enabled, set the expire timer to make this
|
|
|
|
connection's speed get checked again in a second */
|
2017-06-08 14:34:32 +08:00
|
|
|
Curl_expire(data, 1000, EXPIRE_SPEEDCHECK);
|
2017-04-05 06:42:34 +08:00
|
|
|
|
2000-05-22 22:12:12 +08:00
|
|
|
return CURLE_OK;
|
1999-12-29 22:20:26 +08:00
|
|
|
}
|