bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainenlog_throttle_init(const struct log_throttle_settings *set,
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen log_throttle_callback_t *callback, void *context)
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen i_assert(set->throttle_at_max_per_interval > 0);
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen i_assert(set->unthrottle_at_max_per_interval > 0);
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainenvoid log_throttle_deinit(struct log_throttle **_throttle)
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainenstatic void log_throttle_callback(struct log_throttle *throttle)
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen throttle->callback(throttle->last_count, throttle->context);
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen if (throttle->last_count < throttle->set.unthrottle_at_max_per_interval)
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainenbool log_throttle_accept(struct log_throttle *throttle)
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen /* unthrottling and last_count resets are done only by
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen the callback */
ed1e909434714837f583c9d180c2a16a1c2675c2Timo Sirainen } else if (timeval_diff_msecs(&ioloop_timeval, &throttle->last_time) >=