mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Functions to track the total bytes sent over a rate limit group.
This commit is contained in:
parent
33874b0528
commit
fb366c1d88
@ -79,6 +79,13 @@ struct bufferevent_rate_limit_group {
|
||||
* again. */
|
||||
unsigned pending_unsuspend_write : 1;
|
||||
|
||||
/*@{*/
|
||||
/** Total number of bytes read or written in this group since last
|
||||
* reset. */
|
||||
ev_uint64_t total_read;
|
||||
ev_uint64_t total_written;
|
||||
/*@}*/
|
||||
|
||||
/** The number of bufferevents in the group. */
|
||||
int n_members;
|
||||
|
||||
|
@ -282,6 +282,7 @@ _bufferevent_decrement_read_buckets(struct bufferevent_private *bev, int bytes)
|
||||
if (bev->rate_limiting->group) {
|
||||
LOCK_GROUP(bev->rate_limiting->group);
|
||||
bev->rate_limiting->group->rate_limit.read_limit -= bytes;
|
||||
bev->rate_limiting->group->total_read += bytes;
|
||||
if (bev->rate_limiting->group->rate_limit.read_limit <= 0) {
|
||||
_bev_group_suspend_reading(bev->rate_limiting->group);
|
||||
}
|
||||
@ -313,6 +314,7 @@ _bufferevent_decrement_write_buckets(struct bufferevent_private *bev, int bytes)
|
||||
if (bev->rate_limiting->group) {
|
||||
LOCK_GROUP(bev->rate_limiting->group);
|
||||
bev->rate_limiting->group->rate_limit.write_limit -= bytes;
|
||||
bev->rate_limiting->group->total_written += bytes;
|
||||
if (bev->rate_limiting->group->rate_limit.write_limit <= 0) {
|
||||
_bev_group_suspend_writing(bev->rate_limiting->group);
|
||||
}
|
||||
@ -908,3 +910,19 @@ bufferevent_rate_limit_group_decrement_write(
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
bufferevent_rate_limit_group_get_totals(struct bufferevent_rate_limit_group *grp,
|
||||
ev_uint64_t *total_read_out, ev_uint64_t *total_written_out)
|
||||
{
|
||||
EVUTIL_ASSERT(grp != NULL);
|
||||
if (total_read_out)
|
||||
*total_read_out = grp->total_read;
|
||||
if (total_written_out)
|
||||
*total_written_out = grp->total_written;
|
||||
}
|
||||
|
||||
void
|
||||
bufferevent_rate_limit_group_reset_totals(struct bufferevent_rate_limit_group *grp)
|
||||
{
|
||||
grp->total_read = grp->total_written = 0;
|
||||
}
|
||||
|
@ -674,6 +674,19 @@ int bufferevent_rate_limit_group_decrement_write(
|
||||
/*@}*/
|
||||
|
||||
|
||||
/** Set the variable pointed to by total_read_out to the total number of bytes
|
||||
* ever read on grp, and the variable pointed to by total_written_out to the
|
||||
* total number of bytes ever written on grp. */
|
||||
void bufferevent_rate_limit_group_get_totals(
|
||||
struct bufferevent_rate_limit_group *grp,
|
||||
ev_uint64_t *total_read_out, ev_uint64_t *total_written_out);
|
||||
|
||||
/** Reset the number of bytes read or written on grp as given by
|
||||
* bufferevent_rate_limit_group_reset_totals(). */
|
||||
void
|
||||
bufferevent_rate_limit_group_reset_totals(
|
||||
struct bufferevent_rate_limit_group *grp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user