29 size_t target_byte_rate;
31 struct timespec container_zero_time;
32 struct timespec container_last_time;
38 _nmsg_brate_init(
size_t target_byte_rate) {
41 b = calloc(1,
sizeof(*b));
44 b->target_byte_rate = target_byte_rate;
51 _nmsg_brate_destroy(
struct nmsg_brate **b) {
59 _nmsg_brate_sleep(
struct nmsg_brate *b,
72 struct timespec container_time = now;
87 b->t_time = (container_sz + 0.0) / (b->target_byte_rate);
92 if (c_time < b->t_time)
96 b->qu = QUANTUM * n_payloads;
103 b->container_zero_time = now;
104 }
else if ((n % b->qu) == 0 || n == n_payloads - 1) {
115 frac = (n + 0.0) / n_payloads;
127 t_time_frac = frac * b->t_time;
134 s_time = t_time_frac - e_time;
142 if (n == n_payloads - 1) {
void nmsg_timespec_get(struct timespec *ts)
Get the current time.
void nmsg_timespec_from_double(double seconds, struct timespec *ts)
Convert floating point number of seconds to timespec.
double nmsg_timespec_to_double(const struct timespec *ts)
Convert timespec to floating point representation.
void nmsg_timespec_sleep(const struct timespec *ts)
Sleep.
void nmsg_timespec_sub(const struct timespec *a, struct timespec *b)
Subtract timespec b from a, placing result in b.