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