Lines Matching defs:bw
878 bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen)
880 bw->buflen = buflen;
881 bw->rate = kbps;
882 bw->thresh = bw->rate;
883 bw->lamt = 0;
884 timerclear(&bw->bwstart);
885 timerclear(&bw->bwend);
890 bandwidth_limit(struct bwlimit *bw, size_t read_len)
895 if (!timerisset(&bw->bwstart)) {
896 gettimeofday(&bw->bwstart, NULL);
900 bw->lamt += read_len;
901 if (bw->lamt < bw->thresh)
904 gettimeofday(&bw->bwend, NULL);
905 timersub(&bw->bwend, &bw->bwstart, &bw->bwend);
906 if (!timerisset(&bw->bwend))
909 bw->lamt *= 8;
910 waitlen = (double)1000000L * bw->lamt / bw->rate;
912 bw->bwstart.tv_sec = waitlen / 1000000L;
913 bw->bwstart.tv_usec = waitlen % 1000000L;
915 if (timercmp(&bw->bwstart, &bw->bwend, >)) {
916 timersub(&bw->bwstart, &bw->bwend, &bw->bwend);
919 if (bw->bwend.tv_sec) {
920 bw->thresh /= 2;
921 if (bw->thresh < bw->buflen / 4)
922 bw->thresh = bw->buflen / 4;
923 } else if (bw->bwend.tv_usec < 10000) {
924 bw->thresh *= 2;
925 if (bw->thresh > bw->buflen * 8)
926 bw->thresh = bw->buflen * 8;
929 TIMEVAL_TO_TIMESPEC(&bw->bwend, &ts);
937 bw->lamt = 0;
938 gettimeofday(&bw->bwstart, NULL);