1 /* pump - copy through circular buffer */
7 Lock arithlock; /* protect 64-bit accesses: unlikely to be atomic */
27 fprint(2, "usage: pump [-f ofile] [-k KB-buffer] [-i ireadsize]\n"
28 "\t[-o owritesize] [-b iando] [-s start-KB] [-d sleeptime] "
34 main(int argc, char *argv[])
40 obsize = ibsize = 8*1024;
48 obsize = ibsize = atoi(EARGF(usage()));
51 dsize = atoi(EARGF(usage()));
54 file = EARGF(usage());
55 fo = create(file, 1, 0666);
57 sysfatal("can't create %s: %r", file);
60 ibsize = atoi(EARGF(usage()));
63 kilo = atoi(EARGF(usage()));
66 obsize = atoi(EARGF(usage()));
69 ssize = atoi(EARGF(usage()));
75 tsize = atoll(EARGF(usage()));
76 tsize *= 10584000; /* minutes */
83 sysfatal("no memory: %r");
89 switch(rfork(RFPROC|RFNOWAIT|RFNAMEG|RFMEM)) {
94 for(i=0; i<argc; i++) {
95 f = open(argv[i], OREAD);
97 fprint(2, "%s: can't open %s: %r\n",
108 fprint(2, "%s: fork failed: %r\n", argv0);
115 /* call with arithlock held */
117 sleepunlocked(long ms)
138 sleepunlocked(dsize);
141 if(verb && n > max) {
142 fprint(2, "n = %ld\n", n);
152 c = write(f, buf+l, n);
156 fprint(2, "%s: write error: %r\n", argv0);
160 if(tsize && nout > tsize) {
161 fprint(2, "%s: time limit exceeded\n", argv0);
175 for (xnin = 0; xnin < ssize && !done; xnin += c) {
176 n = kilo - (xnin - nout);
186 c = read(f, buf+l, n);
191 fprint(2, "%s: read error: %r\n", argv0);
198 n = kilo - (nin - nout);
210 c = read(f, buf+l, n);
215 fprint(2, "%s: read error: %r\n", argv0);