diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-09-12 12:39:57 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-09-12 12:39:57 +0100 |
commit | 138b68aa5a49d96cd913cad0a563eeec84d019fc (patch) | |
tree | 6d484c1f168315a6a9065d30c4829ee3eb4b3c66 /src | |
parent | eb8358834ce9f393b22c94e75837ae664e14d471 (diff) | |
download | rspamd-138b68aa5a49d96cd913cad0a563eeec84d019fc.tar.gz rspamd-138b68aa5a49d96cd913cad0a563eeec84d019fc.zip |
[Minor] Redis_pool: Slightly improve style
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/redis_pool.cxx | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/libserver/redis_pool.cxx b/src/libserver/redis_pool.cxx index a3c5a7ebb..84e101105 100644 --- a/src/libserver/redis_pool.cxx +++ b/src/libserver/redis_pool.cxx @@ -96,6 +96,7 @@ class redis_pool_elt { */ std::list<redis_pool_connection_ptr> active; std::list<redis_pool_connection_ptr> inactive; + std::list<redis_pool_connection_ptr> terminating; std::string ip; std::string db; std::string password; @@ -121,19 +122,31 @@ public: auto new_connection() -> redisAsyncContext *; - auto release_active(const redis_pool_connection *conn) -> void + auto release_connection(const redis_pool_connection *conn) -> void { - active.erase(conn->elt_pos); + switch(conn->state) { + case RSPAMD_REDIS_POOL_CONN_ACTIVE: + active.erase(conn->elt_pos); + break; + case RSPAMD_REDIS_POOL_CONN_INACTIVE: + inactive.erase(conn->elt_pos); + break; + case RSPAMD_REDIS_POOL_CONN_FINALISING: + terminating.erase(conn->elt_pos); + break; + } } - auto release_inactive(const redis_pool_connection *conn) -> void + auto move_to_inactive(redis_pool_connection *conn) -> void { - inactive.erase(conn->elt_pos); + inactive.splice(std::end(inactive), active, conn->elt_pos); + conn->elt_pos = std::prev(std::end(inactive)); } - auto move_to_inactive(const redis_pool_connection *conn) -> void + auto move_to_terminating(redis_pool_connection *conn) -> void { - inactive.splice(std::end(inactive), active, conn->elt_pos); + inactive.splice(std::end(inactive), terminating, conn->elt_pos); + conn->elt_pos = std::prev(std::end(terminating)); } inline static auto make_key(const gchar *db, const gchar *password, @@ -308,6 +321,7 @@ redis_pool_connection::redis_conn_timeout_cb(EV_P_ ev_timer *w, int revents) -> conn->state = RSPAMD_REDIS_POOL_CONN_FINALISING; ev_timer_again(EV_A_ w); redisAsyncCommand(conn->ctx, redis_pool_connection::redis_quit_cb, conn, "QUIT"); + conn->elt->move_to_terminating(conn); } else { /* Finalising by timeout */ @@ -316,7 +330,7 @@ redis_pool_connection::redis_conn_timeout_cb(EV_P_ ev_timer *w, int revents) -> conn->ctx); /* Erasure of shared pointer will cause it to be removed */ - conn->elt->release_inactive(conn); + conn->elt->release_connection(conn); } } @@ -338,7 +352,7 @@ redis_pool_connection::redis_on_disconnect(const struct redisAsyncContext *ac, i } /* Erasure of shared pointer will cause it to be removed */ - conn->elt->release_inactive(conn); + conn->elt->release_connection(conn); } } @@ -523,7 +537,7 @@ auto redis_pool::release_connection(redisAsyncContext *ctx, } } - conn->elt->release_active(conn); + conn->elt->release_connection(conn); } else { RSPAMD_UNREACHABLE; |