Commit 4bd44b9c authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Convert dispatch state to enum class

parent 1b42110d
...@@ -135,7 +135,7 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool, ...@@ -135,7 +135,7 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool,
affinity_cookie_(0), affinity_cookie_(0),
request_state_(DownstreamState::INITIAL), request_state_(DownstreamState::INITIAL),
response_state_(DownstreamState::INITIAL), response_state_(DownstreamState::INITIAL),
dispatch_state_(DISPATCH_NONE), dispatch_state_(DispatchState::NONE),
upgraded_(false), upgraded_(false),
chunked_request_(false), chunked_request_(false),
chunked_response_(false), chunked_response_(false),
...@@ -1067,9 +1067,9 @@ bool Downstream::request_submission_ready() const { ...@@ -1067,9 +1067,9 @@ bool Downstream::request_submission_ready() const {
response_state_ == DownstreamState::INITIAL; response_state_ == DownstreamState::INITIAL;
} }
int Downstream::get_dispatch_state() const { return dispatch_state_; } DispatchState Downstream::get_dispatch_state() const { return dispatch_state_; }
void Downstream::set_dispatch_state(int s) { dispatch_state_ = s; } void Downstream::set_dispatch_state(DispatchState s) { dispatch_state_ = s; }
void Downstream::attach_blocked_link(BlockedLink *l) { void Downstream::attach_blocked_link(BlockedLink *l) {
assert(!blocked_link_); assert(!blocked_link_);
......
...@@ -292,6 +292,14 @@ enum class DownstreamState { ...@@ -292,6 +292,14 @@ enum class DownstreamState {
HTTP1_REQUEST_HEADER_TOO_LARGE, HTTP1_REQUEST_HEADER_TOO_LARGE,
}; };
enum class DispatchState {
NONE,
PENDING,
BLOCKED,
ACTIVE,
FAILURE,
};
class Downstream { class Downstream {
public: public:
Downstream(Upstream *upstream, MemchunkPool *mcpool, int32_t stream_id); Downstream(Upstream *upstream, MemchunkPool *mcpool, int32_t stream_id);
...@@ -448,8 +456,8 @@ public: ...@@ -448,8 +456,8 @@ public:
// true if retry attempt should not be done. // true if retry attempt should not be done.
bool no_more_retry() const; bool no_more_retry() const;
int get_dispatch_state() const; DispatchState get_dispatch_state() const;
void set_dispatch_state(int s); void set_dispatch_state(DispatchState s);
void attach_blocked_link(BlockedLink *l); void attach_blocked_link(BlockedLink *l);
BlockedLink *detach_blocked_link(); BlockedLink *detach_blocked_link();
...@@ -490,14 +498,6 @@ public: ...@@ -490,14 +498,6 @@ public:
EVENT_TIMEOUT = 0x2, EVENT_TIMEOUT = 0x2,
}; };
enum {
DISPATCH_NONE,
DISPATCH_PENDING,
DISPATCH_BLOCKED,
DISPATCH_ACTIVE,
DISPATCH_FAILURE,
};
Downstream *dlnext, *dlprev; Downstream *dlnext, *dlprev;
// the length of response body sent to upstream client // the length of response body sent to upstream client
...@@ -561,7 +561,7 @@ private: ...@@ -561,7 +561,7 @@ private:
// response state // response state
DownstreamState response_state_; DownstreamState response_state_;
// only used by HTTP/2 upstream // only used by HTTP/2 upstream
int dispatch_state_; DispatchState dispatch_state_;
// true if the connection is upgraded (HTTP Upgrade or CONNECT), // true if the connection is upgraded (HTTP Upgrade or CONNECT),
// excluding upgrade to HTTP/2. // excluding upgrade to HTTP/2.
bool upgraded_; bool upgraded_;
......
...@@ -49,12 +49,12 @@ DownstreamQueue::~DownstreamQueue() { ...@@ -49,12 +49,12 @@ DownstreamQueue::~DownstreamQueue() {
} }
void DownstreamQueue::add_pending(std::unique_ptr<Downstream> downstream) { void DownstreamQueue::add_pending(std::unique_ptr<Downstream> downstream) {
downstream->set_dispatch_state(Downstream::DISPATCH_PENDING); downstream->set_dispatch_state(DispatchState::PENDING);
downstreams_.append(downstream.release()); downstreams_.append(downstream.release());
} }
void DownstreamQueue::mark_failure(Downstream *downstream) { void DownstreamQueue::mark_failure(Downstream *downstream) {
downstream->set_dispatch_state(Downstream::DISPATCH_FAILURE); downstream->set_dispatch_state(DispatchState::FAILURE);
} }
DownstreamQueue::HostEntry & DownstreamQueue::HostEntry &
...@@ -87,13 +87,13 @@ void DownstreamQueue::mark_active(Downstream *downstream) { ...@@ -87,13 +87,13 @@ void DownstreamQueue::mark_active(Downstream *downstream) {
auto &ent = find_host_entry(make_host_key(downstream)); auto &ent = find_host_entry(make_host_key(downstream));
++ent.num_active; ++ent.num_active;
downstream->set_dispatch_state(Downstream::DISPATCH_ACTIVE); downstream->set_dispatch_state(DispatchState::ACTIVE);
} }
void DownstreamQueue::mark_blocked(Downstream *downstream) { void DownstreamQueue::mark_blocked(Downstream *downstream) {
auto &ent = find_host_entry(make_host_key(downstream)); auto &ent = find_host_entry(make_host_key(downstream));
downstream->set_dispatch_state(Downstream::DISPATCH_BLOCKED); downstream->set_dispatch_state(DispatchState::BLOCKED);
auto link = new BlockedLink{}; auto link = new BlockedLink{};
downstream->attach_blocked_link(link); downstream->attach_blocked_link(link);
...@@ -131,7 +131,7 @@ Downstream *DownstreamQueue::remove_and_get_blocked(Downstream *downstream, ...@@ -131,7 +131,7 @@ Downstream *DownstreamQueue::remove_and_get_blocked(Downstream *downstream,
auto host = make_host_key(downstream); auto host = make_host_key(downstream);
auto &ent = find_host_entry(host); auto &ent = find_host_entry(host);
if (downstream->get_dispatch_state() == Downstream::DISPATCH_ACTIVE) { if (downstream->get_dispatch_state() == DispatchState::ACTIVE) {
--ent.num_active; --ent.num_active;
} else { } else {
// For those downstreams deleted while in blocked state // For those downstreams deleted while in blocked state
......
...@@ -88,10 +88,10 @@ public: ...@@ -88,10 +88,10 @@ public:
// |host|. // |host|.
bool can_activate(const StringRef &host) const; bool can_activate(const StringRef &host) const;
// Removes and frees |downstream| object. If |downstream| is in // Removes and frees |downstream| object. If |downstream| is in
// Downstream::DISPATCH_ACTIVE, and |next_blocked| is true, this // DispatchState::ACTIVE, and |next_blocked| is true, this function
// function may return Downstream object with the same target host // may return Downstream object with the same target host in
// in Downstream::DISPATCH_BLOCKED if its connection is now not // DispatchState::BLOCKED if its connection is now not blocked by
// blocked by conn_max_per_host_ limit. // conn_max_per_host_ limit.
Downstream *remove_and_get_blocked(Downstream *downstream, Downstream *remove_and_get_blocked(Downstream *downstream,
bool next_blocked = true); bool next_blocked = true);
Downstream *get_downstreams() const; Downstream *get_downstreams() const;
......
...@@ -2025,7 +2025,7 @@ int Http2Upstream::on_timeout(Downstream *downstream) { ...@@ -2025,7 +2025,7 @@ int Http2Upstream::on_timeout(Downstream *downstream) {
void Http2Upstream::on_handler_delete() { void Http2Upstream::on_handler_delete() {
for (auto d = downstream_queue_.get_downstreams(); d; d = d->dlnext) { for (auto d = downstream_queue_.get_downstreams(); d; d = d->dlnext) {
if (d->get_dispatch_state() == Downstream::DISPATCH_ACTIVE && if (d->get_dispatch_state() == DispatchState::ACTIVE &&
d->accesslog_ready()) { d->accesslog_ready()) {
handler_->write_accesslog(d); handler_->write_accesslog(d);
} }
...@@ -2035,10 +2035,10 @@ void Http2Upstream::on_handler_delete() { ...@@ -2035,10 +2035,10 @@ void Http2Upstream::on_handler_delete() {
int Http2Upstream::on_downstream_reset(Downstream *downstream, bool no_retry) { int Http2Upstream::on_downstream_reset(Downstream *downstream, bool no_retry) {
int rv; int rv;
if (downstream->get_dispatch_state() != Downstream::DISPATCH_ACTIVE) { if (downstream->get_dispatch_state() != DispatchState::ACTIVE) {
// This is error condition when we failed push_request_headers() // This is error condition when we failed push_request_headers()
// in initiate_downstream(). Otherwise, we have // in initiate_downstream(). Otherwise, we have
// Downstream::DISPATCH_ACTIVE state, or we did not set // DispatchState::ACTIVE state, or we did not set
// DownstreamConnection. // DownstreamConnection.
downstream->pop_downstream_connection(); downstream->pop_downstream_connection();
handler_->signal_write(); handler_->signal_write();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment