2002-09-03 15:52:59 +04:00
|
|
|
/***************************************************************************
|
2004-10-06 11:50:18 +04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
1999-12-29 17:20:26 +03:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2017-04-05 01:42:34 +03:00
|
|
|
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
1999-12-29 17:20:26 +03:00
|
|
|
*
|
2002-09-03 15:52:59 +04:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 02:19:02 +03:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-10-06 11:50:18 +04:00
|
|
|
*
|
2001-01-03 12:29:33 +03: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 15:52:59 +04:00
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
1999-12-29 17:20:26 +03:00
|
|
|
*
|
2001-01-03 12:29:33 +03:00
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
1999-12-29 17:20:26 +03:00
|
|
|
*
|
2002-09-03 15:52:59 +04:00
|
|
|
***************************************************************************/
|
1999-12-29 17:20:26 +03:00
|
|
|
|
2013-01-06 22:06:49 +04:00
|
|
|
#include "curl_setup.h"
|
2000-08-24 18:26:33 +04:00
|
|
|
|
1999-12-29 17:20:26 +03:00
|
|
|
#include <curl/curl.h>
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "speedcheck.h"
|
1999-12-29 17:20:26 +03:00
|
|
|
|
2016-06-21 16:47:12 +03:00
|
|
|
void Curl_speedinit(struct Curl_easy *data)
|
2000-10-17 18:53:03 +04:00
|
|
|
{
|
2017-07-28 16:49:36 +03:00
|
|
|
memset(&data->state.keeps_speed, 0, sizeof(struct curltime));
|
2000-10-17 18:53:03 +04:00
|
|
|
}
|
|
|
|
|
2017-04-05 01:42:34 +03:00
|
|
|
/*
|
|
|
|
* @unittest: 1606
|
|
|
|
*/
|
2016-06-21 16:47:12 +03:00
|
|
|
CURLcode Curl_speedcheck(struct Curl_easy *data,
|
2017-07-28 16:49:36 +03:00
|
|
|
struct curltime now)
|
1999-12-29 17:20:26 +03:00
|
|
|
{
|
2017-04-05 01:42:34 +03: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 13:05:49 +03:00
|
|
|
timediff_t howlong = Curl_timediff(now, data->state.keeps_speed);
|
1999-12-29 17:20:26 +03:00
|
|
|
|
2017-04-05 01:42:34 +03: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 17:20:26 +03:00
|
|
|
}
|
2017-04-05 01:42:34 +03:00
|
|
|
else
|
|
|
|
/* faster right now */
|
|
|
|
data->state.keeps_speed.tv_sec = 0;
|
1999-12-29 17:20:26 +03:00
|
|
|
}
|
2006-10-17 13:05:44 +04:00
|
|
|
|
2017-04-05 01:42:34 +03: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 09:34:32 +03:00
|
|
|
Curl_expire(data, 1000, EXPIRE_SPEEDCHECK);
|
2017-04-05 01:42:34 +03:00
|
|
|
|
2000-05-22 18:12:12 +04:00
|
|
|
return CURLE_OK;
|
1999-12-29 17:20:26 +03:00
|
|
|
}
|