nghttpx: Convert connection check status to enum class

This commit is contained in:
Tatsuhiro Tsujikawa 2018-10-17 11:08:56 +09:00
parent 4bd075defd
commit e62258713e
2 changed files with 25 additions and 26 deletions

View File

@ -69,7 +69,7 @@ void connchk_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
ev_timer_stop(loop, w);
switch (http2session->get_connection_check_state()) {
case Http2Session::CONNECTION_CHECK_STARTED:
case ConnectionCheck::STARTED:
// ping timeout; disconnect
if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "ping timeout";
@ -82,8 +82,7 @@ void connchk_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "connection check required";
}
http2session->set_connection_check_state(
Http2Session::CONNECTION_CHECK_REQUIRED);
http2session->set_connection_check_state(ConnectionCheck::REQUIRED);
}
}
} // namespace
@ -198,7 +197,7 @@ Http2Session::Http2Session(struct ev_loop *loop, SSL_CTX *ssl_ctx,
session_(nullptr),
raddr_(nullptr),
state_(Http2SessionState::DISCONNECTED),
connection_check_state_(CONNECTION_CHECK_NONE),
connection_check_state_(ConnectionCheck::NONE),
freelist_zone_(FreelistZone::NONE),
settings_recved_(false),
allow_connect_proto_(false) {
@ -266,7 +265,7 @@ int Http2Session::disconnect(bool hard) {
proxy_htp_.reset();
}
connection_check_state_ = CONNECTION_CHECK_NONE;
connection_check_state_ = ConnectionCheck::NONE;
state_ = Http2SessionState::DISCONNECTED;
// When deleting Http2DownstreamConnection, it calls this object's
@ -1867,16 +1866,16 @@ int Http2Session::consume(int32_t stream_id, size_t len) {
bool Http2Session::can_push_request(const Downstream *downstream) const {
auto &req = downstream->request();
return state_ == Http2SessionState::CONNECTED &&
connection_check_state_ == CONNECTION_CHECK_NONE &&
connection_check_state_ == ConnectionCheck::NONE &&
(req.connect_proto == ConnectProto::NONE || settings_recved_);
}
void Http2Session::start_checking_connection() {
if (state_ != Http2SessionState::CONNECTED ||
connection_check_state_ != CONNECTION_CHECK_REQUIRED) {
connection_check_state_ != ConnectionCheck::REQUIRED) {
return;
}
connection_check_state_ = CONNECTION_CHECK_STARTED;
connection_check_state_ = ConnectionCheck::STARTED;
SSLOG(INFO, this) << "Start checking connection";
// If connection is down, we may get error when writing data. Issue
@ -1895,7 +1894,7 @@ void Http2Session::reset_connection_check_timer(ev_tstamp t) {
}
void Http2Session::reset_connection_check_timer_if_not_checking() {
if (connection_check_state_ != CONNECTION_CHECK_NONE) {
if (connection_check_state_ != ConnectionCheck::NONE) {
return;
}
@ -1905,7 +1904,7 @@ void Http2Session::reset_connection_check_timer_if_not_checking() {
void Http2Session::connection_alive() {
reset_connection_check_timer(CONNCHK_TIMEOUT);
if (connection_check_state_ == CONNECTION_CHECK_NONE) {
if (connection_check_state_ == ConnectionCheck::NONE) {
return;
}
@ -1913,7 +1912,7 @@ void Http2Session::connection_alive() {
SSLOG(INFO, this) << "Connection alive";
}
connection_check_state_ = CONNECTION_CHECK_NONE;
connection_check_state_ = ConnectionCheck::NONE;
submit_pending_requests();
}
@ -1948,11 +1947,11 @@ void Http2Session::submit_pending_requests() {
}
}
void Http2Session::set_connection_check_state(int state) {
void Http2Session::set_connection_check_state(ConnectionCheck state) {
connection_check_state_ = state;
}
int Http2Session::get_connection_check_state() const {
ConnectionCheck Http2Session::get_connection_check_state() const {
return connection_check_state_;
}

View File

@ -91,6 +91,15 @@ enum class Http2SessionState {
RESOLVING_NAME,
};
enum class ConnectionCheck {
// Connection checking is not required
NONE,
// Connection checking is required
REQUIRED,
// Connection checking has been started
STARTED,
};
class Http2Session {
public:
Http2Session(struct ev_loop *loop, SSL_CTX *ssl_ctx, Worker *worker,
@ -178,8 +187,8 @@ public:
// reset_connection_check_timer() is called.
void connection_alive();
// Change connection check state.
void set_connection_check_state(int state);
int get_connection_check_state() const;
void set_connection_check_state(ConnectionCheck state);
ConnectionCheck get_connection_check_state() const;
bool should_hard_fail() const;
@ -237,15 +246,6 @@ public:
bool get_allow_connect_proto() const;
enum {
// Connection checking is not required
CONNECTION_CHECK_NONE,
// Connection checking is required
CONNECTION_CHECK_REQUIRED,
// Connection checking has been started
CONNECTION_CHECK_STARTED
};
using ReadBuf = Buffer<8_k>;
Http2Session *dlnext, *dlprev;
@ -255,7 +255,7 @@ private:
DefaultMemchunks wb_;
ev_timer settings_timer_;
// This timer has 2 purpose: when it first timeout, set
// connection_check_state_ = CONNECTION_CHECK_REQUIRED. After
// connection_check_state_ = ConnectionCheck::REQUIRED. After
// connection check has started, this timer is started again and
// traps PING ACK timeout.
ev_timer connchk_timer_;
@ -284,7 +284,7 @@ private:
std::unique_ptr<Address> resolved_addr_;
std::unique_ptr<DNSQuery> dns_query_;
Http2SessionState state_;
int connection_check_state_;
ConnectionCheck connection_check_state_;
FreelistZone freelist_zone_;
// true if SETTINGS without ACK is received from peer.
bool settings_recved_;