From 0f75997839320a75bb827ad120f586915be6a2aa Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 13 Sep 2013 00:25:24 +0900 Subject: [PATCH] nghttpx: Share ev_token_bucket_cfg across ClientHandlers --- src/shrpx.cc | 4 ++++ src/shrpx_client_handler.cc | 7 +------ src/shrpx_client_handler.h | 1 - src/shrpx_config.h | 3 +++ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index cb2ec7bd..156ad854 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -400,6 +400,10 @@ void fill_default_config() mod_config()->downstream_http_proxy_host = 0; mod_config()->downstream_http_proxy_port = 0; mod_config()->downstream_http_proxy_addrlen = 0; + mod_config()->rate_limit_cfg = + ev_token_bucket_cfg_new(1024*1024, 4*1024*1024, + EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, + nullptr); } } // namespace diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index fa5ef96b..dea6e640 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -212,10 +212,6 @@ void upstream_http1_connhd_readcb(bufferevent *bev, void *arg) ClientHandler::ClientHandler(bufferevent *bev, int fd, SSL *ssl, const char *ipaddr) : bev_(bev), - evbucket_cfg_(ev_token_bucket_cfg_new(1024*1024, 4*1024*1024, - EV_RATE_LIMIT_MAX, - EV_RATE_LIMIT_MAX, - nullptr)), fd_(fd), ssl_(ssl), upstream_(nullptr), @@ -224,7 +220,7 @@ ClientHandler::ClientHandler(bufferevent *bev, int fd, SSL *ssl, spdy_(nullptr), left_connhd_len_(NGHTTP2_CLIENT_CONNECTION_HEADER_LEN) { - bufferevent_set_rate_limit(bev_, evbucket_cfg_); + bufferevent_set_rate_limit(bev_, get_config()->rate_limit_cfg); bufferevent_enable(bev_, EV_READ | EV_WRITE); bufferevent_setwatermark(bev_, EV_READ, 0, SHRPX_READ_WARTER_MARK); set_upstream_timeouts(&get_config()->upstream_read_timeout, @@ -250,7 +246,6 @@ ClientHandler::~ClientHandler() } bufferevent_disable(bev_, EV_READ | EV_WRITE); bufferevent_free(bev_); - ev_token_bucket_cfg_free(evbucket_cfg_); if(ssl_) { SSL_free(ssl_); } diff --git a/src/shrpx_client_handler.h b/src/shrpx_client_handler.h index 8c3261f9..00115d5f 100644 --- a/src/shrpx_client_handler.h +++ b/src/shrpx_client_handler.h @@ -76,7 +76,6 @@ public: bool get_http2_upgrade_allowed() const; private: bufferevent *bev_; - ev_token_bucket_cfg *evbucket_cfg_; int fd_; SSL *ssl_; Upstream *upstream_; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index c0cd6905..08cb29e4 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -34,6 +34,7 @@ #include #include +#include #include namespace shrpx { @@ -167,6 +168,8 @@ struct Config { sockaddr_union downstream_http_proxy_addr; // actual size of downstream_http_proxy_addr size_t downstream_http_proxy_addrlen; + // Rate limit configuration + ev_token_bucket_cfg *rate_limit_cfg; }; const Config* get_config();