diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-02-21 15:08:21 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-02-21 15:08:21 +0000 |
commit | 243bd5bbb46cfb792c1c636f43b02c9834a0e0dd (patch) | |
tree | 83086fd3315bc03ef8b293cb0418d01b3d21b06b | |
parent | 4bde770169c05653726956c9bf866aec19ddfe1c (diff) |
David Byron's fix to allow the speed-limit logic work even if you set
limit-rate. It does work on the expense of the rate limiter.
-rw-r--r-- | src/main.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c index b539c9804..ded76944c 100644 --- a/src/main.c +++ b/src/main.c @@ -133,6 +133,14 @@ typedef char bool; #define CURL_PROGRESS_STATS 0 /* default progress display */ #define CURL_PROGRESS_BAR 1 +/** + * @def MIN + * standard MIN macro + */ +#ifndef MIN +#define MIN(X,Y) (((X) < (Y)) ? (X) : (Y)) +#endif + typedef enum { HTTPREQ_UNSPEC, HTTPREQ_GET, @@ -2220,12 +2228,23 @@ static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) time_t timediff; time_t now; + time_t sleep_time; now = time(NULL); timediff = now - config->lastrecvtime; if( size*nmemb > config->recvpersecond*timediff) { /* figure out how many milliseconds to rest */ - go_sleep ( (size*nmemb)*1000/config->recvpersecond - timediff*1000 ); + sleep_time = (size*nmemb)*1000/config->recvpersecond - timediff*1000; + + /* + * Make sure we don't sleep for so long that we trigger the speed limit. + * This won't limit the bandwidth quite the way we've been asked to, but + * at least the transfer has a chance. + */ + if (config->low_speed_time > 0) + sleep_time = MIN(sleep_time,(config->low_speed_time * 1000) / 2); + + go_sleep (sleep_time); now = time(NULL); } config->lastrecvtime = now; |