[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 134/150: limit-rate: kick in even before "limit" da
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 134/150: limit-rate: kick in even before "limit" data has been received |
Date: |
Fri, 30 Mar 2018 16:49:48 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 72a0f6251aed97b21b94dfa0c35ccc42fb8d9728
Author: Daniel Stenberg <address@hidden>
AuthorDate: Sat Mar 10 14:07:38 2018 +0100
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
---
lib/progress.c | 40 +++++++++++++++++++++++-----------------
lib/progress.h | 12 ++++++------
2 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/lib/progress.c b/lib/progress.c
index eef2ca7d4..0ac0c469f 100644
--- a/lib/progress.c
+++ b/lib/progress.c
@@ -238,8 +238,8 @@ void Curl_pgrsStartNow(struct Curl_easy *data)
}
/*
- * This is used to handle speed limits, calculating how much milliseconds we
- * need to wait until we're back under the speed limit, if needed.
+ * This is used to handle speed limits, calculating how many milliseconds to
+ * 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
* 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
* and the current time.
*
- * Returns -1 if no waiting is needed (not enough data transferred since
- * starting point yet), 0 when no waiting is needed but the starting point
- * should be reset (to current), or the number of milliseconds to wait to get
- * back under the speed limit.
+ * Returns 0 if no waiting is needed or when no waiting is needed but the
+ * starting point should be reset (to current); or the number of milliseconds
+ * to wait to get back under the speed limit.
*/
-long Curl_pgrsLimitWaitTime(curl_off_t cursize,
- curl_off_t startsize,
- curl_off_t limit,
- struct curltime start,
- struct curltime now)
+timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
+ curl_off_t startsize,
+ curl_off_t limit,
+ struct curltime start,
+ struct curltime now)
{
curl_off_t size = cursize - startsize;
time_t minimum;
@@ -270,16 +269,23 @@ long Curl_pgrsLimitWaitTime(curl_off_t cursize,
if(start.tv_sec == 0 && start.tv_usec == 0)
return 0;
- /* not enough data yet */
- if(size < limit)
- return -1;
+ if(!limit)
+ return 0;
+
+ 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);
if(actual < minimum)
- /* this is a conversion on some systems (64bit time_t => 32bit long) */
- return (long)(minimum - actual);
+ return (minimum - actual);
return 0;
}
diff --git a/lib/progress.h b/lib/progress.h
index 9333ab25c..3c2231cb6 100644
--- a/lib/progress.h
+++ b/lib/progress.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <address@hidden>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <address@hidden>, et al.
*
* This software is licensed as described in the file COPYING, which
* 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 *);
void Curl_pgrsResetTransferSizes(struct Curl_easy *data);
void Curl_pgrsTime(struct Curl_easy *data, timerid timer);
-long Curl_pgrsLimitWaitTime(curl_off_t cursize,
- curl_off_t startsize,
- curl_off_t limit,
- struct curltime start,
- struct curltime now);
+timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
+ curl_off_t startsize,
+ curl_off_t limit,
+ struct curltime start,
+ struct curltime now);
/* Don't show progress for sizes smaller than: */
#define LEAST_SIZE_PROGRESS BUFSIZE
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 118/150: NO_PROXY: fix for IPv6 numericals in the URL, (continued)
- [GNUnet-SVN] [gnurl] 118/150: NO_PROXY: fix for IPv6 numericals in the URL, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 132/150: SECURITY.md: call it the security process, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 100/150: lib: CURLOPT_HAPPY_EYEBALLS_TIMEOUT => CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 117/150: build: get CFLAGS (including -werror) used for examples and tests, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 114/150: unit1309: fix warning on Windows x64, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 135/150: BUGS: updated link to security process, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 142/150: FAQ: fix a broken URL [ci skip], gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 145/150: limit-rate: fix compiler warning, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 140/150: credits: Viktor prefers without accent, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 138/150: openldap: check ldap_get_attribute_ber() results for NULL before using, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 134/150: limit-rate: kick in even before "limit" data has been received,
gnunet <=
- [GNUnet-SVN] [gnurl] 126/150: curl tool: accept --compressed also if Brotli is enabled and zlib is not., gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 146/150: Revert "hostip: fix compiler warning: 'variable set but not used'", gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 68/150: libcurl-security.3: split out from libcurl-tutorial.3, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 129/150: HTTP: allow "header; " to replace an internal header with a blank one, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 148/150: tests/.../spnego.py: fix identifier typo, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 71/150: libcurl-security.3: separate file:// section, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 66/150: tests: new tests for http raw mode, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 111/150: curl-openssl.m4: Fix version check for OpenSSL 1.1.1, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 127/150: SECURITY: distros' max embargo time is 14 days now, gnunet, 2018/03/30
- [GNUnet-SVN] [gnurl] 110/150: lib655: silence compiler warning, gnunet, 2018/03/30