mirror of
https://gitee.com/openharmony/third_party_nghttp2
synced 2024-12-03 13:41:14 +00:00
nghttpx: Convert dispatch state to enum class
This commit is contained in:
parent
1b42110d4f
commit
4bd44b9cdf
@ -135,7 +135,7 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool,
|
||||
affinity_cookie_(0),
|
||||
request_state_(DownstreamState::INITIAL),
|
||||
response_state_(DownstreamState::INITIAL),
|
||||
dispatch_state_(DISPATCH_NONE),
|
||||
dispatch_state_(DispatchState::NONE),
|
||||
upgraded_(false),
|
||||
chunked_request_(false),
|
||||
chunked_response_(false),
|
||||
@ -1067,9 +1067,9 @@ bool Downstream::request_submission_ready() const {
|
||||
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) {
|
||||
assert(!blocked_link_);
|
||||
|
@ -292,6 +292,14 @@ enum class DownstreamState {
|
||||
HTTP1_REQUEST_HEADER_TOO_LARGE,
|
||||
};
|
||||
|
||||
enum class DispatchState {
|
||||
NONE,
|
||||
PENDING,
|
||||
BLOCKED,
|
||||
ACTIVE,
|
||||
FAILURE,
|
||||
};
|
||||
|
||||
class Downstream {
|
||||
public:
|
||||
Downstream(Upstream *upstream, MemchunkPool *mcpool, int32_t stream_id);
|
||||
@ -448,8 +456,8 @@ public:
|
||||
// true if retry attempt should not be done.
|
||||
bool no_more_retry() const;
|
||||
|
||||
int get_dispatch_state() const;
|
||||
void set_dispatch_state(int s);
|
||||
DispatchState get_dispatch_state() const;
|
||||
void set_dispatch_state(DispatchState s);
|
||||
|
||||
void attach_blocked_link(BlockedLink *l);
|
||||
BlockedLink *detach_blocked_link();
|
||||
@ -490,14 +498,6 @@ public:
|
||||
EVENT_TIMEOUT = 0x2,
|
||||
};
|
||||
|
||||
enum {
|
||||
DISPATCH_NONE,
|
||||
DISPATCH_PENDING,
|
||||
DISPATCH_BLOCKED,
|
||||
DISPATCH_ACTIVE,
|
||||
DISPATCH_FAILURE,
|
||||
};
|
||||
|
||||
Downstream *dlnext, *dlprev;
|
||||
|
||||
// the length of response body sent to upstream client
|
||||
@ -561,7 +561,7 @@ private:
|
||||
// response state
|
||||
DownstreamState response_state_;
|
||||
// only used by HTTP/2 upstream
|
||||
int dispatch_state_;
|
||||
DispatchState dispatch_state_;
|
||||
// true if the connection is upgraded (HTTP Upgrade or CONNECT),
|
||||
// excluding upgrade to HTTP/2.
|
||||
bool upgraded_;
|
||||
|
@ -49,12 +49,12 @@ DownstreamQueue::~DownstreamQueue() {
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
void DownstreamQueue::mark_failure(Downstream *downstream) {
|
||||
downstream->set_dispatch_state(Downstream::DISPATCH_FAILURE);
|
||||
downstream->set_dispatch_state(DispatchState::FAILURE);
|
||||
}
|
||||
|
||||
DownstreamQueue::HostEntry &
|
||||
@ -87,13 +87,13 @@ void DownstreamQueue::mark_active(Downstream *downstream) {
|
||||
auto &ent = find_host_entry(make_host_key(downstream));
|
||||
++ent.num_active;
|
||||
|
||||
downstream->set_dispatch_state(Downstream::DISPATCH_ACTIVE);
|
||||
downstream->set_dispatch_state(DispatchState::ACTIVE);
|
||||
}
|
||||
|
||||
void DownstreamQueue::mark_blocked(Downstream *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{};
|
||||
downstream->attach_blocked_link(link);
|
||||
@ -131,7 +131,7 @@ Downstream *DownstreamQueue::remove_and_get_blocked(Downstream *downstream,
|
||||
auto host = make_host_key(downstream);
|
||||
auto &ent = find_host_entry(host);
|
||||
|
||||
if (downstream->get_dispatch_state() == Downstream::DISPATCH_ACTIVE) {
|
||||
if (downstream->get_dispatch_state() == DispatchState::ACTIVE) {
|
||||
--ent.num_active;
|
||||
} else {
|
||||
// For those downstreams deleted while in blocked state
|
||||
|
@ -88,10 +88,10 @@ public:
|
||||
// |host|.
|
||||
bool can_activate(const StringRef &host) const;
|
||||
// Removes and frees |downstream| object. If |downstream| is in
|
||||
// Downstream::DISPATCH_ACTIVE, and |next_blocked| is true, this
|
||||
// function may return Downstream object with the same target host
|
||||
// in Downstream::DISPATCH_BLOCKED if its connection is now not
|
||||
// blocked by conn_max_per_host_ limit.
|
||||
// DispatchState::ACTIVE, and |next_blocked| is true, this function
|
||||
// may return Downstream object with the same target host in
|
||||
// DispatchState::BLOCKED if its connection is now not blocked by
|
||||
// conn_max_per_host_ limit.
|
||||
Downstream *remove_and_get_blocked(Downstream *downstream,
|
||||
bool next_blocked = true);
|
||||
Downstream *get_downstreams() const;
|
||||
|
@ -2025,7 +2025,7 @@ int Http2Upstream::on_timeout(Downstream *downstream) {
|
||||
|
||||
void Http2Upstream::on_handler_delete() {
|
||||
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()) {
|
||||
handler_->write_accesslog(d);
|
||||
}
|
||||
@ -2035,10 +2035,10 @@ void Http2Upstream::on_handler_delete() {
|
||||
int Http2Upstream::on_downstream_reset(Downstream *downstream, bool no_retry) {
|
||||
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()
|
||||
// in initiate_downstream(). Otherwise, we have
|
||||
// Downstream::DISPATCH_ACTIVE state, or we did not set
|
||||
// DispatchState::ACTIVE state, or we did not set
|
||||
// DownstreamConnection.
|
||||
downstream->pop_downstream_connection();
|
||||
handler_->signal_write();
|
||||
|
Loading…
Reference in New Issue
Block a user