THRIFT-4762: Applied some C++11 refactorings to the runtime library and compiler (#1719)
* make use of C++11 override keyword
* added const specifier to TTransport::getOrigin()
* added more const correctness to the compiler
* make use of auto keyword
* replaced usage of NULL with nullptr
* make use of explicitly-defaulted function definition
* extended changelog
diff --git a/lib/cpp/src/thrift/async/TEvhttpServer.cpp b/lib/cpp/src/thrift/async/TEvhttpServer.cpp
index bdc3266..7d2cf21 100644
--- a/lib/cpp/src/thrift/async/TEvhttpServer.cpp
+++ b/lib/cpp/src/thrift/async/TEvhttpServer.cpp
@@ -46,24 +46,24 @@
};
TEvhttpServer::TEvhttpServer(std::shared_ptr<TAsyncBufferProcessor> processor)
- : processor_(processor), eb_(NULL), eh_(NULL) {
+ : processor_(processor), eb_(nullptr), eh_(nullptr) {
}
TEvhttpServer::TEvhttpServer(std::shared_ptr<TAsyncBufferProcessor> processor, int port)
- : processor_(processor), eb_(NULL), eh_(NULL) {
+ : processor_(processor), eb_(nullptr), eh_(nullptr) {
// Create event_base and evhttp.
eb_ = event_base_new();
- if (eb_ == NULL) {
+ if (eb_ == nullptr) {
throw TException("event_base_new failed");
}
eh_ = evhttp_new(eb_);
- if (eh_ == NULL) {
+ if (eh_ == nullptr) {
event_base_free(eb_);
throw TException("evhttp_new failed");
}
// Bind to port.
- int ret = evhttp_bind_socket(eh_, NULL, port);
+ int ret = evhttp_bind_socket(eh_, nullptr, port);
if (ret < 0) {
evhttp_free(eh_);
event_base_free(eb_);
@@ -77,16 +77,16 @@
}
TEvhttpServer::~TEvhttpServer() {
- if (eh_ != NULL) {
+ if (eh_ != nullptr) {
evhttp_free(eh_);
}
- if (eb_ != NULL) {
+ if (eb_ != nullptr) {
event_base_free(eb_);
}
}
int TEvhttpServer::serve() {
- if (eb_ == NULL) {
+ if (eb_ == nullptr) {
throw TException("Unexpected call to TEvhttpServer::serve");
}
return event_base_dispatch(eb_);
@@ -103,12 +103,12 @@
try {
static_cast<TEvhttpServer*>(self)->process(req);
} catch (std::exception& e) {
- evhttp_send_reply(req, HTTP_INTERNAL, e.what(), 0);
+ evhttp_send_reply(req, HTTP_INTERNAL, e.what(), nullptr);
}
}
void TEvhttpServer::process(struct evhttp_request* req) {
- RequestContext* ctx = new RequestContext(req);
+ auto* ctx = new RequestContext(req);
return processor_->process(std::bind(&TEvhttpServer::complete,
this,
ctx,
@@ -131,7 +131,7 @@
}
struct evbuffer* buf = evbuffer_new();
- if (buf == NULL) {
+ if (buf == nullptr) {
// TODO: Log an error.
std::cerr << "evbuffer_new failed " << __FILE__ << ":" << __LINE__ << std::endl;
} else {
@@ -147,7 +147,7 @@
}
evhttp_send_reply(ctx->req, code, reason, buf);
- if (buf != NULL) {
+ if (buf != nullptr) {
evbuffer_free(buf);
}
}