From owner-freebsd-bugs Wed Mar 5 17:10:12 2003 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A796537B401 for ; Wed, 5 Mar 2003 17:10:07 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9ADB543F3F for ; Wed, 5 Mar 2003 17:10:06 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h261A6NS029171 for ; Wed, 5 Mar 2003 17:10:06 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h261A6gM029170; Wed, 5 Mar 2003 17:10:06 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8221037B401 for ; Wed, 5 Mar 2003 17:05:01 -0800 (PST) Received: from gandalf.eilio.com (gandalf.eilio.com [216.211.130.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id E478C43F85 for ; Wed, 5 Mar 2003 17:05:00 -0800 (PST) (envelope-from philip@gandalf.eilio.com) Received: from gandalf.eilio.com (gandalf.eilio.com [216.211.130.9]) by gandalf.eilio.com (8.12.6/8.12.6) with ESMTP id h26150qs097325 for ; Wed, 5 Mar 2003 17:05:00 -0800 (PST) (envelope-from philip@gandalf.eilio.com) Received: (from philip@localhost) by gandalf.eilio.com (8.12.6/8.12.6/Submit) id h261508I097324; Wed, 5 Mar 2003 17:05:00 -0800 (PST) Message-Id: <200303060105.h261508I097324@gandalf.eilio.com> Date: Wed, 5 Mar 2003 17:05:00 -0800 (PST) From: Philip Hallstrom Reply-To: Philip Hallstrom To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/48962: [PATCH] modify /usr/bin/fetch to allow bandwidth limiting Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 >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