mirror of
https://github.com/moparisthebest/curl
synced 2024-11-17 06:55:02 -05:00
limit-rate: kick in even before "limit" data has been received
... and make sure to avoid integer overflows with really large values. Reported-by: 刘佩东 Fixes #2371 Closes #2373
This commit is contained in:
parent
029ae11034
commit
72a0f6251a
@ -238,8 +238,8 @@ void Curl_pgrsStartNow(struct Curl_easy *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is used to handle speed limits, calculating how much milliseconds we
|
* This is used to handle speed limits, calculating how many milliseconds to
|
||||||
* need to wait until we're back under the speed limit, if needed.
|
* wait until we're back under the speed limit, if needed.
|
||||||
*
|
*
|
||||||
* The way it works is by having a "starting point" (time & amount of data
|
* The way it works is by having a "starting point" (time & amount of data
|
||||||
* transferred by then) used in the speed computation, to be used instead of
|
* transferred by then) used in the speed computation, to be used instead of
|
||||||
@ -251,16 +251,15 @@ void Curl_pgrsStartNow(struct Curl_easy *data)
|
|||||||
* the starting point, the limit (in bytes/s), the time of the starting point
|
* the starting point, the limit (in bytes/s), the time of the starting point
|
||||||
* and the current time.
|
* and the current time.
|
||||||
*
|
*
|
||||||
* Returns -1 if no waiting is needed (not enough data transferred since
|
* Returns 0 if no waiting is needed or when no waiting is needed but the
|
||||||
* starting point yet), 0 when no waiting is needed but the starting point
|
* starting point should be reset (to current); or the number of milliseconds
|
||||||
* should be reset (to current), or the number of milliseconds to wait to get
|
* to wait to get back under the speed limit.
|
||||||
* back under the speed limit.
|
|
||||||
*/
|
*/
|
||||||
long Curl_pgrsLimitWaitTime(curl_off_t cursize,
|
timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
|
||||||
curl_off_t startsize,
|
curl_off_t startsize,
|
||||||
curl_off_t limit,
|
curl_off_t limit,
|
||||||
struct curltime start,
|
struct curltime start,
|
||||||
struct curltime now)
|
struct curltime now)
|
||||||
{
|
{
|
||||||
curl_off_t size = cursize - startsize;
|
curl_off_t size = cursize - startsize;
|
||||||
time_t minimum;
|
time_t minimum;
|
||||||
@ -270,16 +269,23 @@ long Curl_pgrsLimitWaitTime(curl_off_t cursize,
|
|||||||
if(start.tv_sec == 0 && start.tv_usec == 0)
|
if(start.tv_sec == 0 && start.tv_usec == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* not enough data yet */
|
if(!limit)
|
||||||
if(size < limit)
|
return 0;
|
||||||
return -1;
|
|
||||||
|
if(size < CURL_OFF_T_MAX/1000)
|
||||||
|
minimum = (time_t) (CURL_OFF_T_C(1000) * size / limit);
|
||||||
|
else {
|
||||||
|
minimum = (time_t) (size / limit);
|
||||||
|
if(minimum < TIME_T_MAX/1000)
|
||||||
|
minimum *= CURL_OFF_T_C(1000);
|
||||||
|
else
|
||||||
|
minimum = TIME_T_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
minimum = (time_t) (CURL_OFF_T_C(1000) * size / limit);
|
|
||||||
actual = Curl_timediff(now, start);
|
actual = Curl_timediff(now, start);
|
||||||
|
|
||||||
if(actual < minimum)
|
if(actual < minimum)
|
||||||
/* this is a conversion on some systems (64bit time_t => 32bit long) */
|
return (minimum - actual);
|
||||||
return (long)(minimum - actual);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@ -49,11 +49,11 @@ void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size);
|
|||||||
int Curl_pgrsUpdate(struct connectdata *);
|
int Curl_pgrsUpdate(struct connectdata *);
|
||||||
void Curl_pgrsResetTransferSizes(struct Curl_easy *data);
|
void Curl_pgrsResetTransferSizes(struct Curl_easy *data);
|
||||||
void Curl_pgrsTime(struct Curl_easy *data, timerid timer);
|
void Curl_pgrsTime(struct Curl_easy *data, timerid timer);
|
||||||
long Curl_pgrsLimitWaitTime(curl_off_t cursize,
|
timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
|
||||||
curl_off_t startsize,
|
curl_off_t startsize,
|
||||||
curl_off_t limit,
|
curl_off_t limit,
|
||||||
struct curltime start,
|
struct curltime start,
|
||||||
struct curltime now);
|
struct curltime now);
|
||||||
|
|
||||||
/* Don't show progress for sizes smaller than: */
|
/* Don't show progress for sizes smaller than: */
|
||||||
#define LEAST_SIZE_PROGRESS BUFSIZE
|
#define LEAST_SIZE_PROGRESS BUFSIZE
|
||||||
|
Loading…
Reference in New Issue
Block a user