nghttpx: Use std::mt19937 instead of std::random_device directly
This commit is contained in:
parent
a23c9244d4
commit
1550d709e0
|
@ -102,8 +102,12 @@ void thread_join_async_cb(struct ev_loop *loop, ev_async *w, int revent) {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::random_device rd;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
ConnectionHandler::ConnectionHandler(struct ev_loop *loop)
|
ConnectionHandler::ConnectionHandler(struct ev_loop *loop)
|
||||||
: single_worker_(nullptr), loop_(loop),
|
: gen_(rd()), single_worker_(nullptr), loop_(loop),
|
||||||
tls_ticket_key_memcached_get_retry_count_(0),
|
tls_ticket_key_memcached_get_retry_count_(0),
|
||||||
tls_ticket_key_memcached_fail_count_(0), worker_round_robin_cnt_(0),
|
tls_ticket_key_memcached_fail_count_(0), worker_round_robin_cnt_(0),
|
||||||
graceful_shutdown_(false) {
|
graceful_shutdown_(false) {
|
||||||
|
@ -667,10 +671,6 @@ ConnectionHandler::get_tls_ticket_key_memcached_dispatcher() const {
|
||||||
return tls_ticket_key_memcached_dispatcher_.get();
|
return tls_ticket_key_memcached_dispatcher_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
std::random_device rd;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void ConnectionHandler::on_tls_ticket_key_network_error(ev_timer *w) {
|
void ConnectionHandler::on_tls_ticket_key_network_error(ev_timer *w) {
|
||||||
if (++tls_ticket_key_memcached_get_retry_count_ >=
|
if (++tls_ticket_key_memcached_get_retry_count_ >=
|
||||||
get_config()->tls_ticket_key_memcached_max_retry) {
|
get_config()->tls_ticket_key_memcached_max_retry) {
|
||||||
|
@ -683,7 +683,7 @@ void ConnectionHandler::on_tls_ticket_key_network_error(ev_timer *w) {
|
||||||
|
|
||||||
auto dist = std::uniform_int_distribution<int>(
|
auto dist = std::uniform_int_distribution<int>(
|
||||||
1, std::min(60, 1 << tls_ticket_key_memcached_get_retry_count_));
|
1, std::min(60, 1 << tls_ticket_key_memcached_get_retry_count_));
|
||||||
auto t = dist(rd);
|
auto t = dist(gen_);
|
||||||
|
|
||||||
LOG(WARN)
|
LOG(WARN)
|
||||||
<< "Memcached: tls ticket get failed due to network error, retrying in "
|
<< "Memcached: tls ticket get failed due to network error, retrying in "
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <random>
|
||||||
#ifndef NOTHREADS
|
#ifndef NOTHREADS
|
||||||
#include <future>
|
#include <future>
|
||||||
#endif // NOTHREADS
|
#endif // NOTHREADS
|
||||||
|
@ -139,6 +140,7 @@ private:
|
||||||
// Stores all SSL_CTX objects.
|
// Stores all SSL_CTX objects.
|
||||||
std::vector<SSL_CTX *> all_ssl_ctx_;
|
std::vector<SSL_CTX *> all_ssl_ctx_;
|
||||||
OCSPUpdateContext ocsp_;
|
OCSPUpdateContext ocsp_;
|
||||||
|
std::mt19937 gen_;
|
||||||
// ev_loop for each worker
|
// ev_loop for each worker
|
||||||
std::vector<struct ev_loop *> worker_loops_;
|
std::vector<struct ev_loop *> worker_loops_;
|
||||||
// Worker instances when multi threaded mode (-nN, N >= 2) is used.
|
// Worker instances when multi threaded mode (-nN, N >= 2) is used.
|
||||||
|
|
Loading…
Reference in New Issue