From 4b3d5af8e2ccc5a6ec29922869bdeac40d15c854 Mon Sep 17 00:00:00 2001 From: Mark Ellzey Date: Thu, 11 Jul 2013 12:31:39 -0400 Subject: [PATCH] Add function to fetch underlying ratelimit cfg bufferevent_get_token_bucket_cfg() will return the struct ev_token_bucket_cfg for a bufferevent if available. --- bufferevent_ratelim.c | 17 +++++++++++++++++ include/event2/bufferevent.h | 2 ++ test/test-ratelim.c | 2 ++ 3 files changed, 21 insertions(+) diff --git a/bufferevent_ratelim.c b/bufferevent_ratelim.c index 28fc0356..bc81334c 100644 --- a/bufferevent_ratelim.c +++ b/bufferevent_ratelim.c @@ -924,6 +924,23 @@ bufferevent_get_max_to_write(struct bufferevent *bev) return r; } +struct ev_token_bucket_cfg * +bufferevent_get_token_bucket_cfg(struct bufferevent *bev) { + struct bufferevent_private *bufev_private = BEV_UPCAST(bev); + struct ev_token_bucket_cfg *cfg; + + BEV_LOCK(bev); + + if (bufev_private->rate_limiting) { + cfg = bufev_private->rate_limiting->cfg; + } else { + cfg = NULL; + } + + BEV_UNLOCK(bev); + + return cfg; +} /* Mostly you don't want to use this function from inside libevent; * bufferevent_get_read_max_() is more likely what you want*/ diff --git a/include/event2/bufferevent.h b/include/event2/bufferevent.h index 4ed4e5d1..78436001 100644 --- a/include/event2/bufferevent.h +++ b/include/event2/bufferevent.h @@ -795,6 +795,8 @@ ev_ssize_t bufferevent_get_write_limit(struct bufferevent *bev); ev_ssize_t bufferevent_get_max_to_read(struct bufferevent *bev); ev_ssize_t bufferevent_get_max_to_write(struct bufferevent *bev); +struct ev_token_bucket_cfg *bufferevent_get_token_bucket_cfg(struct bufferevent * bev); + /** @name Group Rate limit inspection diff --git a/test/test-ratelim.c b/test/test-ratelim.c index aa171aa4..27649b84 100644 --- a/test/test-ratelim.c +++ b/test/test-ratelim.c @@ -187,6 +187,8 @@ echo_listenercb(struct evconnlistener *listener, evutil_socket_t newsock, struct event *check_event = event_new(base, -1, EV_PERSIST, check_bucket_levels_cb, bev); bufferevent_set_rate_limit(bev, conn_bucket_cfg); + + assert(bufferevent_get_token_bucket_cfg(bev) != NULL); event_add(check_event, ms100_common); } if (ratelim_group) -- 2.40.0