|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
令牌桶数据结构 更多...
#include <rate_limiter.hpp>
Public 成员函数 | |
| bool | try_consume (uint64_t now_ms) |
| 尝试消耗一个令牌 | |
| void | refill (uint64_t now_ms) |
| 补充令牌(基于时间差) | |
Public 属性 | |
| double | tokens {0.} |
| 当前令牌数 | |
| uint64_t | last_refill_ms {0} |
| 上次补充时间(毫秒时间戳) | |
| double | refill_rate {1.} |
| 每秒补充令牌数 | |
| double | capacity {1.} |
| 桶容量 | |
| mutex | mutex_ |
| 保护内部状态 | |
| void neforce::http::token_bucket::refill | ( | uint64_t | now_ms | ) |
补充令牌(基于时间差)
| now_ms | 当前时间 |
| bool neforce::http::token_bucket::try_consume | ( | uint64_t | now_ms | ) |
尝试消耗一个令牌
| now_ms | 当前时间(毫秒时间戳) |
先补充令牌(基于时间差),再尝试消耗。