diff options
-rw-r--r-- | misc.c | 9 | ||||
-rw-r--r-- | misc.h | 6 |
2 files changed, 8 insertions, 7 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.134 2018/11/16 03:26:01 djm Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.135 2018/12/07 04:36:09 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -1335,11 +1335,11 @@ bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen) | |||
1335 | { | 1335 | { |
1336 | bw->buflen = buflen; | 1336 | bw->buflen = buflen; |
1337 | bw->rate = kbps; | 1337 | bw->rate = kbps; |
1338 | bw->thresh = bw->rate; | 1338 | bw->thresh = buflen; |
1339 | bw->lamt = 0; | 1339 | bw->lamt = 0; |
1340 | timerclear(&bw->bwstart); | 1340 | timerclear(&bw->bwstart); |
1341 | timerclear(&bw->bwend); | 1341 | timerclear(&bw->bwend); |
1342 | } | 1342 | } |
1343 | 1343 | ||
1344 | /* Callback from read/write loop to insert bandwidth-limiting delays */ | 1344 | /* Callback from read/write loop to insert bandwidth-limiting delays */ |
1345 | void | 1345 | void |
@@ -1348,12 +1348,11 @@ bandwidth_limit(struct bwlimit *bw, size_t read_len) | |||
1348 | u_int64_t waitlen; | 1348 | u_int64_t waitlen; |
1349 | struct timespec ts, rm; | 1349 | struct timespec ts, rm; |
1350 | 1350 | ||
1351 | bw->lamt += read_len; | ||
1351 | if (!timerisset(&bw->bwstart)) { | 1352 | if (!timerisset(&bw->bwstart)) { |
1352 | monotime_tv(&bw->bwstart); | 1353 | monotime_tv(&bw->bwstart); |
1353 | return; | 1354 | return; |
1354 | } | 1355 | } |
1355 | |||
1356 | bw->lamt += read_len; | ||
1357 | if (bw->lamt < bw->thresh) | 1356 | if (bw->lamt < bw->thresh) |
1358 | return; | 1357 | return; |
1359 | 1358 | ||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.h,v 1.76 2018/11/16 03:26:01 djm Exp $ */ | 1 | /* $OpenBSD: misc.h,v 1.77 2018/12/07 04:36:09 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -135,7 +135,9 @@ void put_u32_le(void *, u_int32_t) | |||
135 | 135 | ||
136 | struct bwlimit { | 136 | struct bwlimit { |
137 | size_t buflen; | 137 | size_t buflen; |
138 | u_int64_t rate, thresh, lamt; | 138 | u_int64_t rate; /* desired rate in kbit/s */ |
139 | u_int64_t thresh; /* threshold after which we'll check timers */ | ||
140 | u_int64_t lamt; /* amount written in last timer interval */ | ||
139 | struct timeval bwstart, bwend; | 141 | struct timeval bwstart, bwend; |
140 | }; | 142 | }; |
141 | 143 | ||