[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
rate limit in copy.c
From: |
maurizio panniello |
Subject: |
rate limit in copy.c |
Date: |
Sat, 17 Jun 2006 19:31:11 +0200 (CEST) |
Hi all,
I made a little modification to copy.c and cp.c to
implement in cp the specification of a precise
transfer rate coping normal files.
It is used as:
cp infiles outfiles --rate NBYTESPERSECOND
I need this to don't overload my server copying lots
of files between filesystems. I know i can do this in
other manners (a pipe) but i think is very usefull to
have this directly in cp command directly.
I'm not a programmer only a physic so sorry if my
implementation is bad. (and my english poor ;)
Bye
Maurizio Panniello
Diff from cvs:
------------------------------------------------------
Index: cp.c
===================================================================
RCS file: /sources/coreutils/coreutils/src/cp.c,v
retrieving revision 1.221
diff -r1.221 cp.c
77c77,78
< UNLINK_DEST_BEFORE_OPENING
---
> UNLINK_DEST_BEFORE_OPENING,
> RATE_OPTION
144a146
> {"rate", required_argument, NULL, RATE_OPTION},
747a750
> x->ratelimit = 0;
1003a1007,1010
>
> case RATE_OPTION:
> x.ratelimit = atol(optarg);
> break;
Index: copy.h
===================================================================
RCS file: /sources/coreutils/coreutils/src/copy.h,v
retrieving revision 1.35
diff -r1.35 copy.h
190a191,194
>
> /* This select the copy rate for copy, in bytes
per second */
> long ratelimit;
>
Index: copy.c
===================================================================
RCS file: /sources/coreutils/coreutils/src/copy.c,v
retrieving revision 1.200
diff -r1.200 copy.c
23a24
> #include <time.h>
54a56
> #include "xnanosleep.h"
232a235,241
> double xclock()
> {
> struct timeval tv;
> gettimeofday(&tv,NULL);
> return (double)tv.tv_sec+(double)tv.tv_usec/1e6;
> }
>
335a345,349
> /* rate limitation */
> double t0;
> double rec = 0.;
> size_t incn = 0;
>
390a405
> t0=xclock();
455a471,486
>
> if (x->ratelimit != 0)
> {
> incn+=n;
> if (incn > x->ratelimit / 20.) /* we
make the pause every 20th of second aprox*/
> {
> double dt = (double)(xclock() -
t0);
> double pause = incn /
(double)x->ratelimit - dt + rec;
> rec = xclock();
> incn=0;
> if (pause > 1E-6)
> xnanosleep(pause);
> t0 = xclock();
> rec = pause - (t0 - rec); /*
recuperation time if system too slow */
> }
> }
-----------------------------------------------------
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
- rate limit in copy.c,
maurizio panniello <=