diff -upNr ../../wget-1.5.3-original/src/connect.c ./connect.c --- ../../wget-1.5.3-original/src/connect.c Sun Mar 29 23:28:15 1998 +++ ./connect.c Sun Oct 1 09:54:49 2000 @@ -232,7 +232,23 @@ int iread (int fd, char *buf, int len) { int res; + static time_t lastaccess = 0; /* last second measured */ + static int received = 0; /* bytes received last second */ + static int iteration = 0; + static int bytes_per_iteration; + static int iterations_per_second; + if (!lastaccess) + lastaccess = time(0); + if (!opt.bandwidth_wait) + opt.bandwidth_wait = 50; + + iterations_per_second = 1000 / opt.bandwidth_wait; + bytes_per_iteration = ( opt.bandwidth_limit / (iterations_per_second+1) ); + + if (opt.bandwidth_limit > 0 && len < bytes_per_iteration) + opt.bandwidth_wait -= 10; + do { #ifdef HAVE_SELECT @@ -252,11 +268,39 @@ iread (int fd, char *buf, int len) return -1; } } + if (opt.bandwidth_limit) + { + struct timeval tv; + + if ( received >= bytes_per_iteration ) + { + bzero(&tv, sizeof(struct timeval)); + tv.tv_sec = opt.bandwidth_wait / 1000; /* full seconds */ + tv.tv_usec = (opt.bandwidth_wait % 1000) * 1000; /* microseconds */ + + select(0, NULL, NULL, NULL, &tv); + + received = 0; + iteration++; + } + if (len > bytes_per_iteration-received) + len = bytes_per_iteration-received; + } #endif res = READ (fd, buf, len); } while (res == -1 && errno == EINTR); + if (opt.bandwidth_limit) + { + received += res; /* increment received counter */ + if (lastaccess != time(0) && iteration >= iterations_per_second ) + { + iteration = 0; + lastaccess = time(0); + received = 0; + } + } return res; } diff -upNr ../../wget-1.5.3-original/src/init.c ./init.c --- ../../wget-1.5.3-original/src/init.c Fri Sep 11 02:20:23 1998 +++ ./init.c Sun Oct 1 09:56:01 2000 @@ -213,6 +213,11 @@ defaults (void) opt.dot_bytes = 1024; opt.dot_spacing = 10; opt.dots_in_line = 50; + + /* : bandwidth limitation */ + opt.bandwidth_limit = 0; /* unlimited */ + opt.bandwidth_wait = 200; /* wait 200ms by default */ + } /* Return the user's home directory (strdup-ed), or NULL if none is diff -upNr ../../wget-1.5.3-original/src/main.c ./main.c --- ../../wget-1.5.3-original/src/main.c Fri Sep 11 03:41:53 1998 +++ ./main.c Fri Apr 21 11:57:35 2000 @@ -144,6 +144,7 @@ Download:\n\ -w, --wait=SECONDS wait SECONDS between retrievals.\n\ -Y, --proxy=on/off turn proxy on or off.\n\ -Q, --quota=NUMBER set retrieval quota to NUMBER.\n\ + --bandwidth=NUMBER set the bandwidth limit in BYTES per sec\n\ \n"), _("\ Directories:\n\ -nd --no-directories don\'t create directories.\n\ @@ -234,6 +235,7 @@ main (int argc, char *const *argv) { "accept", required_argument, NULL, 'A' }, { "append-output", required_argument, NULL, 'a' }, { "backups", required_argument, NULL, 23 }, /* undocumented */ + { "bandwidth", required_argument, NULL, 24 }, { "base", required_argument, NULL, 'B' }, { "cache", required_argument, NULL, 'C' }, { "cut-dirs", required_argument, NULL, 17 }, @@ -436,6 +438,9 @@ GNU General Public License for more deta case 23: setval ("backups", optarg); break; + case 24: /* bandwidth limitation */ + opt.bandwidth_limit = atoi(optarg); + break; case 'A': setval ("accept", optarg); break; diff -upNr ../../wget-1.5.3-original/src/options.h ./options.h --- ../../wget-1.5.3-original/src/options.h Tue Apr 28 23:29:40 1998 +++ ./options.h Sun Oct 1 10:01:00 2000 @@ -132,6 +132,9 @@ struct options int delete_after; /* Whether the files will be deleted after download. */ + int bandwidth_limit; /* : bandwidth limitation in kb */ + int bandwidth_wait; /* : milliseconds to wait when + bandwidth limit es reached */ }; #ifndef OPTIONS_DEFINED_HERE