Date: Wed, 5 Mar 2003 17:05:00 -0800 (PST) From: Philip Hallstrom <philip@gandalf.eilio.com> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/48962: [PATCH] modify /usr/bin/fetch to allow bandwidth limiting Message-ID: <200303060105.h261508I097324@gandalf.eilio.com>
next in thread | raw e-mail | index | archive | help
>Number: 48962 >Category: bin >Synopsis: [PATCH] modify /usr/bin/fetch to allow bandwidth limiting >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Wed Mar 05 17:10:06 PST 2003 >Closed-Date: >Last-Modified: >Originator: Philip Hallstrom <philip@eilio.com> >Release: FreeBSD 4.7-20030128-STABLE i386 >Organization: >Environment: System: FreeBSD gandalf.eilio.com 4.7-20030128-STABLE FreeBSD 4.7-20030128-STABLE #0: Fri Feb 7 10:56:11 PST 2003 root@warden.adhesivemedia.com:/usr/obj/usr/src/sys/WARDEN i386 >Description: This is a patch to /usr/bin/fetch to allow limiting the amount of bandwidth used during the transfer. The following command would restrict fetch to only using 20000 bytes/sec (or very close to that). fetch -L 20000 http://domain/file I've been transfering a lot of files over DSL and without this I can't do much else while fetch is running since it takes all the bandwidth (naturally). I've never done this before so if you need anything else let me know. >How-To-Repeat: >Fix: The following are patches to the following files: /usr/src/usr.bin/fetch/fetch.c v 1.10.2.20 2002/12/04 10:28:00 des Exp /usr/src/usr.bin/fetch/fetch.1 v 1.33.2.11 2002/06/20 23:45:50 charnier Exp --- fetch.c.diff begins here --- *** fetch.c-orig Wed Mar 5 14:40:30 2003 --- fetch.c Wed Mar 5 16:43:04 2003 *************** *** 80,85 **** --- 80,86 ---- pid_t pgrp; /* our process group */ long w_secs; /* -w: retry delay */ int family = PF_UNSPEC; /* -[46]: address family to use */ + long limit_rate = 0; /* -L: limit download to N bytes/sec */ int sigalrm; /* SIGALRM received */ int siginfo; /* SIGINFO received */ *************** *** 282,287 **** --- 283,291 ---- u_int timeout; u_char *ptr; + struct timeval limit_tv_now; + float limit_elapsed; + f = of = NULL; tmppath = NULL; *************** *** 548,554 **** --- 552,569 ---- else break; } + stat_update(&xs, count += size); + + /* If desired limit the amount of bandwidth used. */ + if( limit_rate > 0 ) { + gettimeofday(&limit_tv_now, NULL); + limit_elapsed = ((limit_tv_now.tv_sec - xs.start.tv_sec) + (limit_tv_now.tv_usec - xs.start.tv_usec) / 1000000.0) ; + if( xs.rcvd / limit_elapsed > limit_rate ) { + usleep(1000000 * (xs.rcvd / (float) limit_rate - limit_elapsed)); + } + } + for (ptr = buf; size > 0; ptr += wr, size -= wr) if ((wr = fwrite(ptr, 1, size, of)) < size) { if (ferror(of) && errno == EINTR && !sigint) *************** *** 655,661 **** { fprintf(stderr, "%s\n%s\n%s\n", "usage: fetch [-146AFMPRUadlmnpqrsv] [-o outputfile] [-S bytes]", ! " [-B bytes] [-T seconds] [-w seconds]", " [-h host -f file [-c dir] | URL ...]"); } --- 670,676 ---- { fprintf(stderr, "%s\n%s\n%s\n", "usage: fetch [-146AFMPRUadlmnpqrsv] [-o outputfile] [-S bytes]", ! " [-B bytes] [-T seconds] [-w seconds] [-L bytes/sec]", " [-h host -f file [-c dir] | URL ...]"); } *************** *** 673,679 **** int c, e, r; while ((c = getopt(argc, argv, ! "146AaB:bc:dFf:Hh:lMmnPpo:qRrS:sT:tUvw:")) != -1) switch (c) { case '1': once_flag = 1; --- 688,694 ---- int c, e, r; while ((c = getopt(argc, argv, ! "146AaB:bc:dFf:Hh:L:lMmnPpo:qRrS:sT:tUvw:")) != -1) switch (c) { case '1': once_flag = 1; *************** *** 717,722 **** --- 732,742 ---- break; case 'h': h_hostname = optarg; + break; + case 'L': + limit_rate = strtol(optarg, &end, 10); + if (*optarg == '\0' || *end != '\0') + errx(1, "invalid bytes/sec limit (%s)", optarg); break; case 'l': l_flag = 1; --- fetch.c.diff ends here --- --- fetch.1.diff begins here --- *** fetch.1-orig Wed Mar 5 16:43:34 2003 --- fetch.1 Wed Mar 5 16:45:04 2003 *************** *** 107,112 **** --- 107,114 ---- .Ar host . This option is deprecated and is provided for backward compatibility only. + .It Fl L Ar bytes/sec + Limit the transfer rate to bytes/sec. Default (0) is not to limit rate. .It Fl l If the target is a file-scheme URL, make a symbolic link to the target rather than trying to copy it. --- fetch.1.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303060105.h261508I097324>