diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-04-10 18:40:05 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-04-10 20:57:11 +0900 |
commit | 2bfd599ad9264253c455f63adbdf4607db6b2bb7 (patch) | |
tree | 2cf291c856dcc04e38026cc9172fca61a9e8f37a /src/bwlimit.h | |
parent | 9b8ba69a61f09fbcd40574d0b912846eeaaaa1e2 (diff) |
add -L limit bitrate option (#14)
Diffstat (limited to 'src/bwlimit.h')
-rw-r--r-- | src/bwlimit.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bwlimit.h b/src/bwlimit.h new file mode 100644 index 0000000..58cdd8d --- /dev/null +++ b/src/bwlimit.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +#ifndef _BWLIMIT_H_ +#define _BWLIMIT_H_ + +#include <stdbool.h> +#include <stdint.h> +#include <sys/types.h> +#include <time.h> +#include <semaphore.h> + +struct bwlimit { + sem_t *sem; /* semaphore */ + uint64_t bps; /* limit bit-rate (bps) */ + uint64_t win; /* window size (msec) */ + size_t amt; /* amount of bytes can be sent in a window */ + + ssize_t credit; /* remaining bytes can be sent in a window */ + struct timespec wstart, wend; /* window start time and end time */ +}; + +int bwlimit_init(struct bwlimit *bw, uint64_t bps, uint64_t win); +/* if bps is 0, it means that bwlimit is not active. If so, + * bwlimit_wait() returns immediately. */ + +int bwlimit_wait(struct bwlimit *bw, size_t nr_bytes); + + +#endif /* _BWLIMIT_H_ */ |