nghttpx: Code cleanup
This commit is contained in:
parent
888e6f0193
commit
679a389bd3
|
@ -46,7 +46,7 @@ namespace shrpx {
|
||||||
namespace {
|
namespace {
|
||||||
void upstream_readcb(bufferevent *bev, void *arg)
|
void upstream_readcb(bufferevent *bev, void *arg)
|
||||||
{
|
{
|
||||||
ClientHandler *handler = reinterpret_cast<ClientHandler*>(arg);
|
auto handler = reinterpret_cast<ClientHandler*>(arg);
|
||||||
int rv = handler->on_read();
|
int rv = handler->on_read();
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
delete handler;
|
delete handler;
|
||||||
|
@ -57,7 +57,7 @@ void upstream_readcb(bufferevent *bev, void *arg)
|
||||||
namespace {
|
namespace {
|
||||||
void upstream_writecb(bufferevent *bev, void *arg)
|
void upstream_writecb(bufferevent *bev, void *arg)
|
||||||
{
|
{
|
||||||
ClientHandler *handler = reinterpret_cast<ClientHandler*>(arg);
|
auto handler = reinterpret_cast<ClientHandler*>(arg);
|
||||||
// We actually depend on write low-warter mark == 0.
|
// We actually depend on write low-warter mark == 0.
|
||||||
if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) {
|
if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) {
|
||||||
// Possibly because of deferred callback, we may get this callback
|
// Possibly because of deferred callback, we may get this callback
|
||||||
|
@ -67,7 +67,7 @@ void upstream_writecb(bufferevent *bev, void *arg)
|
||||||
if(handler->get_should_close_after_write()) {
|
if(handler->get_should_close_after_write()) {
|
||||||
delete handler;
|
delete handler;
|
||||||
} else {
|
} else {
|
||||||
Upstream *upstream = handler->get_upstream();
|
auto upstream = handler->get_upstream();
|
||||||
int rv = upstream->on_write();
|
int rv = upstream->on_write();
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
delete handler;
|
delete handler;
|
||||||
|
@ -79,7 +79,7 @@ void upstream_writecb(bufferevent *bev, void *arg)
|
||||||
namespace {
|
namespace {
|
||||||
void upstream_eventcb(bufferevent *bev, short events, void *arg)
|
void upstream_eventcb(bufferevent *bev, short events, void *arg)
|
||||||
{
|
{
|
||||||
ClientHandler *handler = reinterpret_cast<ClientHandler*>(arg);
|
auto handler = reinterpret_cast<ClientHandler*>(arg);
|
||||||
bool finish = false;
|
bool finish = false;
|
||||||
if(events & BEV_EVENT_EOF) {
|
if(events & BEV_EVENT_EOF) {
|
||||||
if(LOG_ENABLED(INFO)) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
|
@ -252,9 +252,8 @@ ClientHandler::~ClientHandler()
|
||||||
}
|
}
|
||||||
shutdown(fd_, SHUT_WR);
|
shutdown(fd_, SHUT_WR);
|
||||||
close(fd_);
|
close(fd_);
|
||||||
for(std::set<DownstreamConnection*>::iterator i = dconn_pool_.begin();
|
for(auto dconn : dconn_pool_) {
|
||||||
i != dconn_pool_.end(); ++i) {
|
delete dconn;
|
||||||
delete *i;
|
|
||||||
}
|
}
|
||||||
if(LOG_ENABLED(INFO)) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
CLOG(INFO, this) << "Deleted";
|
CLOG(INFO, this) << "Deleted";
|
||||||
|
@ -382,7 +381,7 @@ DownstreamConnection* ClientHandler::get_downstream_connection()
|
||||||
return new HttpDownstreamConnection(this);
|
return new HttpDownstreamConnection(this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DownstreamConnection *dconn = *dconn_pool_.begin();
|
auto dconn = *std::begin(dconn_pool_);
|
||||||
dconn_pool_.erase(dconn);
|
dconn_pool_.erase(dconn);
|
||||||
if(LOG_ENABLED(INFO)) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
CLOG(INFO, this) << "Reuse downstream connection DCONN:" << dconn
|
CLOG(INFO, this) << "Reuse downstream connection DCONN:" << dconn
|
||||||
|
@ -394,7 +393,7 @@ DownstreamConnection* ClientHandler::get_downstream_connection()
|
||||||
|
|
||||||
size_t ClientHandler::get_pending_write_length()
|
size_t ClientHandler::get_pending_write_length()
|
||||||
{
|
{
|
||||||
evbuffer *output = bufferevent_get_output(bev_);
|
auto output = bufferevent_get_output(bev_);
|
||||||
return evbuffer_get_length(output);
|
return evbuffer_get_length(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace shrpx {
|
||||||
|
|
||||||
DownstreamConnection::DownstreamConnection(ClientHandler *client_handler)
|
DownstreamConnection::DownstreamConnection(ClientHandler *client_handler)
|
||||||
: client_handler_(client_handler),
|
: client_handler_(client_handler),
|
||||||
downstream_(0)
|
downstream_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DownstreamConnection::~DownstreamConnection()
|
DownstreamConnection::~DownstreamConnection()
|
||||||
|
|
|
@ -35,9 +35,8 @@ DownstreamQueue::DownstreamQueue()
|
||||||
|
|
||||||
DownstreamQueue::~DownstreamQueue()
|
DownstreamQueue::~DownstreamQueue()
|
||||||
{
|
{
|
||||||
for(std::map<int32_t, Downstream*>::iterator i = downstreams_.begin();
|
for(auto& kv : downstreams_) {
|
||||||
i != downstreams_.end(); ++i) {
|
delete kv.second;
|
||||||
delete (*i).second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +52,11 @@ void DownstreamQueue::remove(Downstream *downstream)
|
||||||
|
|
||||||
Downstream* DownstreamQueue::find(int32_t stream_id)
|
Downstream* DownstreamQueue::find(int32_t stream_id)
|
||||||
{
|
{
|
||||||
std::map<int32_t, Downstream*>::iterator i = downstreams_.find(stream_id);
|
auto kv = downstreams_.find(stream_id);
|
||||||
if(i == downstreams_.end()) {
|
if(kv == std::end(downstreams_)) {
|
||||||
return 0;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
return (*i).second;
|
return (*kv).second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ Http2DownstreamConnection::Http2DownstreamConnection
|
||||||
(ClientHandler *client_handler)
|
(ClientHandler *client_handler)
|
||||||
: DownstreamConnection(client_handler),
|
: DownstreamConnection(client_handler),
|
||||||
http2session_(client_handler->get_http2_session()),
|
http2session_(client_handler->get_http2_session()),
|
||||||
request_body_buf_(0),
|
request_body_buf_(nullptr),
|
||||||
sd_(0)
|
sd_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Http2DownstreamConnection::~Http2DownstreamConnection()
|
Http2DownstreamConnection::~Http2DownstreamConnection()
|
||||||
|
@ -71,7 +71,7 @@ Http2DownstreamConnection::~Http2DownstreamConnection()
|
||||||
// Downstream and DownstreamConnection may be deleted
|
// Downstream and DownstreamConnection may be deleted
|
||||||
// asynchronously.
|
// asynchronously.
|
||||||
if(downstream_) {
|
if(downstream_) {
|
||||||
downstream_->set_downstream_connection(0);
|
downstream_->set_downstream_connection(nullptr);
|
||||||
}
|
}
|
||||||
if(LOG_ENABLED(INFO)) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
DCLOG(INFO, this) << "Deleted";
|
DCLOG(INFO, this) << "Deleted";
|
||||||
|
@ -89,10 +89,10 @@ int Http2DownstreamConnection::init_request_body_buf()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
request_body_buf_ = evbuffer_new();
|
request_body_buf_ = evbuffer_new();
|
||||||
if(request_body_buf_ == 0) {
|
if(request_body_buf_ == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
evbuffer_setcb(request_body_buf_, 0, this);
|
evbuffer_setcb(request_body_buf_, nullptr, this);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,8 @@ void Http2DownstreamConnection::detach_downstream(Downstream *downstream)
|
||||||
if(submit_rst_stream(downstream) == 0) {
|
if(submit_rst_stream(downstream) == 0) {
|
||||||
http2session_->notify();
|
http2session_->notify();
|
||||||
}
|
}
|
||||||
downstream->set_downstream_connection(0);
|
downstream->set_downstream_connection(nullptr);
|
||||||
downstream_ = 0;
|
downstream_ = nullptr;
|
||||||
|
|
||||||
client_handler_->pool_downstream_connection(this);
|
client_handler_->pool_downstream_connection(this);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ ssize_t http2_data_read_callback(nghttp2_session *session,
|
||||||
}
|
}
|
||||||
// Check dconn is still alive because Upstream::resume_read()
|
// Check dconn is still alive because Upstream::resume_read()
|
||||||
// may delete downstream which will delete dconn.
|
// may delete downstream which will delete dconn.
|
||||||
if(sd->dconn == 0) {
|
if(sd->dconn == nullptr) {
|
||||||
return NGHTTP2_ERR_DEFERRED;
|
return NGHTTP2_ERR_DEFERRED;
|
||||||
}
|
}
|
||||||
if(evbuffer_get_length(body) == 0) {
|
if(evbuffer_get_length(body) == 0) {
|
||||||
|
@ -498,12 +498,12 @@ void Http2DownstreamConnection::attach_stream_data(StreamData *sd)
|
||||||
StreamData* Http2DownstreamConnection::detach_stream_data()
|
StreamData* Http2DownstreamConnection::detach_stream_data()
|
||||||
{
|
{
|
||||||
if(sd_) {
|
if(sd_) {
|
||||||
StreamData *sd = sd_;
|
auto sd = sd_;
|
||||||
sd_ = 0;
|
sd_ = nullptr;
|
||||||
sd->dconn = 0;
|
sd->dconn = nullptr;
|
||||||
return sd;
|
return sd;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue