Commit 679a389b authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Code cleanup

parent 888e6f01
......@@ -46,7 +46,7 @@ namespace shrpx {
namespace {
void upstream_readcb(bufferevent *bev, void *arg)
{
ClientHandler *handler = reinterpret_cast<ClientHandler*>(arg);
auto handler = reinterpret_cast<ClientHandler*>(arg);
int rv = handler->on_read();
if(rv != 0) {
delete handler;
......@@ -57,7 +57,7 @@ void upstream_readcb(bufferevent *bev, void *arg)
namespace {
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.
if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) {
// 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()) {
delete handler;
} else {
Upstream *upstream = handler->get_upstream();
auto upstream = handler->get_upstream();
int rv = upstream->on_write();
if(rv != 0) {
delete handler;
......@@ -79,7 +79,7 @@ void upstream_writecb(bufferevent *bev, void *arg)
namespace {
void upstream_eventcb(bufferevent *bev, short events, void *arg)
{
ClientHandler *handler = reinterpret_cast<ClientHandler*>(arg);
auto handler = reinterpret_cast<ClientHandler*>(arg);
bool finish = false;
if(events & BEV_EVENT_EOF) {
if(LOG_ENABLED(INFO)) {
......@@ -252,9 +252,8 @@ ClientHandler::~ClientHandler()
}
shutdown(fd_, SHUT_WR);
close(fd_);
for(std::set<DownstreamConnection*>::iterator i = dconn_pool_.begin();
i != dconn_pool_.end(); ++i) {
delete *i;
for(auto dconn : dconn_pool_) {
delete dconn;
}
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Deleted";
......@@ -382,7 +381,7 @@ DownstreamConnection* ClientHandler::get_downstream_connection()
return new HttpDownstreamConnection(this);
}
} else {
DownstreamConnection *dconn = *dconn_pool_.begin();
auto dconn = *std::begin(dconn_pool_);
dconn_pool_.erase(dconn);
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Reuse downstream connection DCONN:" << dconn
......@@ -394,7 +393,7 @@ DownstreamConnection* ClientHandler::get_downstream_connection()
size_t ClientHandler::get_pending_write_length()
{
evbuffer *output = bufferevent_get_output(bev_);
auto output = bufferevent_get_output(bev_);
return evbuffer_get_length(output);
}
......
......@@ -31,7 +31,7 @@ namespace shrpx {
DownstreamConnection::DownstreamConnection(ClientHandler *client_handler)
: client_handler_(client_handler),
downstream_(0)
downstream_(nullptr)
{}
DownstreamConnection::~DownstreamConnection()
......
......@@ -35,9 +35,8 @@ DownstreamQueue::DownstreamQueue()
DownstreamQueue::~DownstreamQueue()
{
for(std::map<int32_t, Downstream*>::iterator i = downstreams_.begin();
i != downstreams_.end(); ++i) {
delete (*i).second;
for(auto& kv : downstreams_) {
delete kv.second;
}
}
......@@ -53,11 +52,11 @@ void DownstreamQueue::remove(Downstream *downstream)
Downstream* DownstreamQueue::find(int32_t stream_id)
{
std::map<int32_t, Downstream*>::iterator i = downstreams_.find(stream_id);
if(i == downstreams_.end()) {
return 0;
auto kv = downstreams_.find(stream_id);
if(kv == std::end(downstreams_)) {
return nullptr;
} else {
return (*i).second;
return (*kv).second;
}
}
......
......@@ -50,8 +50,8 @@ Http2DownstreamConnection::Http2DownstreamConnection
(ClientHandler *client_handler)
: DownstreamConnection(client_handler),
http2session_(client_handler->get_http2_session()),
request_body_buf_(0),
sd_(0)
request_body_buf_(nullptr),
sd_(nullptr)
{}
Http2DownstreamConnection::~Http2DownstreamConnection()
......@@ -71,7 +71,7 @@ Http2DownstreamConnection::~Http2DownstreamConnection()
// Downstream and DownstreamConnection may be deleted
// asynchronously.
if(downstream_) {
downstream_->set_downstream_connection(0);
downstream_->set_downstream_connection(nullptr);
}
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Deleted";
......@@ -89,10 +89,10 @@ int Http2DownstreamConnection::init_request_body_buf()
}
} else {
request_body_buf_ = evbuffer_new();
if(request_body_buf_ == 0) {
if(request_body_buf_ == nullptr) {
return -1;
}
evbuffer_setcb(request_body_buf_, 0, this);
evbuffer_setcb(request_body_buf_, nullptr, this);
}
return 0;
}
......@@ -122,8 +122,8 @@ void Http2DownstreamConnection::detach_downstream(Downstream *downstream)
if(submit_rst_stream(downstream) == 0) {
http2session_->notify();
}
downstream->set_downstream_connection(0);
downstream_ = 0;
downstream->set_downstream_connection(nullptr);
downstream_ = nullptr;
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()
// may delete downstream which will delete dconn.
if(sd->dconn == 0) {
if(sd->dconn == nullptr) {
return NGHTTP2_ERR_DEFERRED;
}
if(evbuffer_get_length(body) == 0) {
......@@ -498,12 +498,12 @@ void Http2DownstreamConnection::attach_stream_data(StreamData *sd)
StreamData* Http2DownstreamConnection::detach_stream_data()
{
if(sd_) {
StreamData *sd = sd_;
sd_ = 0;
sd->dconn = 0;
auto sd = sd_;
sd_ = nullptr;
sd->dconn = nullptr;
return sd;
} else {
return 0;
return nullptr;
}
}
......
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