Lines Matching refs:rate_limiting
120 tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); in bufferevent_update_buckets()
121 if (tick != bev->rate_limiting->limit.last_updated) in bufferevent_update_buckets()
122 ev_token_bucket_update_(&bev->rate_limiting->limit, in bufferevent_update_buckets()
123 bev->rate_limiting->cfg, tick); in bufferevent_update_buckets()
216 if (!bev->rate_limiting) in bufferevent_get_rlim_max_()
224 if (bev->rate_limiting->cfg) { in bufferevent_get_rlim_max_()
226 max_so_far = LIM(bev->rate_limiting->limit); in bufferevent_get_rlim_max_()
228 if (bev->rate_limiting->group) { in bufferevent_get_rlim_max_()
230 bev->rate_limiting->group; in bufferevent_get_rlim_max_()
278 if (!bev->rate_limiting) in bufferevent_decrement_read_buckets_()
281 if (bev->rate_limiting->cfg) { in bufferevent_decrement_read_buckets_()
282 bev->rate_limiting->limit.read_limit -= bytes; in bufferevent_decrement_read_buckets_()
283 if (bev->rate_limiting->limit.read_limit <= 0) { in bufferevent_decrement_read_buckets_()
285 if (event_add(&bev->rate_limiting->refill_bucket_event, in bufferevent_decrement_read_buckets_()
286 &bev->rate_limiting->cfg->tick_timeout) < 0) in bufferevent_decrement_read_buckets_()
290 event_del(&bev->rate_limiting->refill_bucket_event); in bufferevent_decrement_read_buckets_()
295 if (bev->rate_limiting->group) { in bufferevent_decrement_read_buckets_()
296 LOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
297 bev->rate_limiting->group->rate_limit.read_limit -= bytes; in bufferevent_decrement_read_buckets_()
298 bev->rate_limiting->group->total_read += bytes; in bufferevent_decrement_read_buckets_()
299 if (bev->rate_limiting->group->rate_limit.read_limit <= 0) { in bufferevent_decrement_read_buckets_()
300 bev_group_suspend_reading_(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
301 } else if (bev->rate_limiting->group->read_suspended) { in bufferevent_decrement_read_buckets_()
302 bev_group_unsuspend_reading_(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
304 UNLOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
316 if (!bev->rate_limiting) in bufferevent_decrement_write_buckets_()
319 if (bev->rate_limiting->cfg) { in bufferevent_decrement_write_buckets_()
320 bev->rate_limiting->limit.write_limit -= bytes; in bufferevent_decrement_write_buckets_()
321 if (bev->rate_limiting->limit.write_limit <= 0) { in bufferevent_decrement_write_buckets_()
323 if (event_add(&bev->rate_limiting->refill_bucket_event, in bufferevent_decrement_write_buckets_()
324 &bev->rate_limiting->cfg->tick_timeout) < 0) in bufferevent_decrement_write_buckets_()
328 event_del(&bev->rate_limiting->refill_bucket_event); in bufferevent_decrement_write_buckets_()
333 if (bev->rate_limiting->group) { in bufferevent_decrement_write_buckets_()
334 LOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
335 bev->rate_limiting->group->rate_limit.write_limit -= bytes; in bufferevent_decrement_write_buckets_()
336 bev->rate_limiting->group->total_written += bytes; in bufferevent_decrement_write_buckets_()
337 if (bev->rate_limiting->group->rate_limit.write_limit <= 0) { in bufferevent_decrement_write_buckets_()
338 bev_group_suspend_writing_(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
339 } else if (bev->rate_limiting->group->write_suspended) { in bufferevent_decrement_write_buckets_()
340 bev_group_unsuspend_writing_(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
342 UNLOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
363 LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { in bev_group_suspend_reading_()
381 LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { in bev_group_suspend_writing_()
401 if (!bev->rate_limiting || !bev->rate_limiting->cfg) { in bev_refill_callback_()
409 bev->rate_limiting->cfg); in bev_refill_callback_()
410 ev_token_bucket_update_(&bev->rate_limiting->limit, in bev_refill_callback_()
411 bev->rate_limiting->cfg, in bev_refill_callback_()
416 if (bev->rate_limiting->limit.read_limit > 0) in bev_refill_callback_()
422 if (bev->rate_limiting->limit.write_limit > 0) in bev_refill_callback_()
435 event_add(&bev->rate_limiting->refill_bucket_event, in bev_refill_callback_()
436 &bev->rate_limiting->cfg->tick_timeout); in bev_refill_callback_()
462 bev = LIST_NEXT(bev, rate_limiting->next_in_group); in bev_group_random_element_()
478 bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \
482 bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \
575 if (bevp->rate_limiting) { in bufferevent_set_rate_limit()
576 rlim = bevp->rate_limiting; in bufferevent_set_rate_limit()
590 if (bevp->rate_limiting && bevp->rate_limiting->cfg == cfg) { in bufferevent_set_rate_limit()
595 if (bevp->rate_limiting == NULL) { in bufferevent_set_rate_limit()
599 bevp->rate_limiting = rlim; in bufferevent_set_rate_limit()
601 rlim = bevp->rate_limiting; in bufferevent_set_rate_limit()
744 if (!bevp->rate_limiting) { in bufferevent_add_to_rate_limit_group()
753 bevp->rate_limiting = rlim; in bufferevent_add_to_rate_limit_group()
756 if (bevp->rate_limiting->group == g) { in bufferevent_add_to_rate_limit_group()
760 if (bevp->rate_limiting->group) in bufferevent_add_to_rate_limit_group()
764 bevp->rate_limiting->group = g; in bufferevent_add_to_rate_limit_group()
766 LIST_INSERT_HEAD(&g->members, bevp, rate_limiting->next_in_group); in bufferevent_add_to_rate_limit_group()
795 if (bevp->rate_limiting && bevp->rate_limiting->group) { in bufferevent_remove_from_rate_limit_group_internal_()
797 bevp->rate_limiting->group; in bufferevent_remove_from_rate_limit_group_internal_()
799 bevp->rate_limiting->group = NULL; in bufferevent_remove_from_rate_limit_group_internal_()
801 LIST_REMOVE(bevp, rate_limiting->next_in_group); in bufferevent_remove_from_rate_limit_group_internal_()
828 if (bevp->rate_limiting && bevp->rate_limiting->cfg) { in bufferevent_get_read_limit()
830 r = bevp->rate_limiting->limit.read_limit; in bufferevent_get_read_limit()
847 if (bevp->rate_limiting && bevp->rate_limiting->cfg) { in bufferevent_get_write_limit()
849 r = bevp->rate_limiting->limit.write_limit; in bufferevent_get_write_limit()
934 if (bufev_private->rate_limiting) { in bufferevent_get_token_bucket_cfg()
935 cfg = bufev_private->rate_limiting->cfg; in bufferevent_get_token_bucket_cfg()
979 EVUTIL_ASSERT(bevp->rate_limiting && bevp->rate_limiting->cfg); in bufferevent_decrement_read_limit()
980 old_limit = bevp->rate_limiting->limit.read_limit; in bufferevent_decrement_read_limit()
982 new_limit = (bevp->rate_limiting->limit.read_limit -= decr); in bufferevent_decrement_read_limit()
985 if (event_add(&bevp->rate_limiting->refill_bucket_event, in bufferevent_decrement_read_limit()
986 &bevp->rate_limiting->cfg->tick_timeout) < 0) in bufferevent_decrement_read_limit()
990 event_del(&bevp->rate_limiting->refill_bucket_event); in bufferevent_decrement_read_limit()
1008 EVUTIL_ASSERT(bevp->rate_limiting && bevp->rate_limiting->cfg); in bufferevent_decrement_write_limit()
1009 old_limit = bevp->rate_limiting->limit.write_limit; in bufferevent_decrement_write_limit()
1011 new_limit = (bevp->rate_limiting->limit.write_limit -= decr); in bufferevent_decrement_write_limit()
1014 if (event_add(&bevp->rate_limiting->refill_bucket_event, in bufferevent_decrement_write_limit()
1015 &bevp->rate_limiting->cfg->tick_timeout) < 0) in bufferevent_decrement_write_limit()
1019 event_del(&bevp->rate_limiting->refill_bucket_event); in bufferevent_decrement_write_limit()
1087 bev->rate_limiting = NULL; in bufferevent_ratelim_init_()