Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/brpc/policy/auto_concurrency_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ AutoConcurrencyLimiter::AutoConcurrencyLimiter()
}

AutoConcurrencyLimiter* AutoConcurrencyLimiter::New(const AdaptiveMaxConcurrency&) const {
return new (std::nothrow) AutoConcurrencyLimiter;
return new AutoConcurrencyLimiter;
}

bool AutoConcurrencyLimiter::OnRequested(int current_concurrency, Controller*) {
Expand Down
60 changes: 26 additions & 34 deletions src/brpc/policy/baidu_rpc_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool SerializeRpcMessage(const google::protobuf::Message& message,
ok = serializer.SerializeTo(&stream);
} else {
const CompressHandler* handler = FindCompressHandler(compress_type);
if (NULL == handler) {
if (nullptr == handler) {
return false;
}
ok = handler->Compress(serializer, buf);
Expand Down Expand Up @@ -232,7 +232,7 @@ static bool SerializeResponse(const google::protobuf::Message& res,
ContentType content_type = cntl.response_content_type();
CompressType compress_type = cntl.response_compress_type();
ChecksumType checksum_type = cntl.response_checksum_type();
const butil::IOBuf* checksum_attachment = NULL;
const butil::IOBuf* checksum_attachment = nullptr;
if (cntl.response_checksum_attachment()) {
// See the same check in SerializeRpcRequest() for the rationale;
// baidu_std never sets this flag itself but we defend anyway.
Expand Down Expand Up @@ -289,8 +289,8 @@ void SendRpcResponse(int64_t correlation_id, Controller* cntl,
}
Socket* sock = accessor.get_sending_socket();

const google::protobuf::Message* req = NULL == messages ? NULL : messages->Request();
const google::protobuf::Message* res = NULL == messages ? NULL : messages->Response();
const google::protobuf::Message* req = nullptr == messages ? nullptr : messages->Request();
const google::protobuf::Message* res = nullptr == messages ? nullptr : messages->Response();

// Recycle resources at the end of this function.
BRPC_SCOPE_EXIT {
Expand All @@ -301,12 +301,12 @@ void SendRpcResponse(int64_t correlation_id, Controller* cntl,

std::unique_ptr<Controller, LogErrorTextAndDelete> recycle_cntl(cntl);

if (NULL == messages) {
if (nullptr == messages) {
return;
}

cntl->CallAfterRpcResp(req, res);
if (NULL == server->options().baidu_master_service) {
if (nullptr == server->options().baidu_master_service) {
server->options().rpc_pb_message_factory->Return(messages);
} else {
BaiduProxyPBMessages::Return(static_cast<BaiduProxyPBMessages*>(messages));
Expand All @@ -324,10 +324,10 @@ void SendRpcResponse(int64_t correlation_id, Controller* cntl,
}
bool append_body = false;
butil::IOBuf res_body;
// `res' can be NULL here, in which case we don't serialize it
// `res' can be nullptr here, in which case we don't serialize it
// If user calls `SetFailed' on Controller, we don't serialize
// response either
if (res != NULL && !cntl->Failed()) {
if (res != nullptr && !cntl->Failed()) {
append_body = SerializeResponse(*res, *cntl, res_body);
}

Expand Down Expand Up @@ -523,7 +523,7 @@ bool DeserializeRpcMessage(const butil::IOBuf& data, Controller& cntl,
ok = deserializer.DeserializeFrom(&stream);
} else {
const CompressHandler* handler = FindCompressHandler(compress_type);
if (NULL == handler) {
if (nullptr == handler) {
return false;
}
ok = handler->Decompress(data, &deserializer);
Expand Down Expand Up @@ -607,13 +607,9 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
sample->submit(start_parse_us);
}

std::unique_ptr<Controller> cntl(new (std::nothrow) Controller);
if (NULL == cntl.get()) {
LOG(WARNING) << "Fail to new Controller";
return;
}
std::unique_ptr<Controller> cntl(new Controller);

RpcPBMessages* messages = NULL;
RpcPBMessages* messages = nullptr;

ServerPrivateAccessor server_accessor(server);
ControllerPrivateAccessor accessor(cntl.get());
Expand Down Expand Up @@ -673,7 +669,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
span->set_request_size(msg->payload.size() + msg->meta.size() + 12);
}

MethodStatus* method_status = NULL;
MethodStatus* method_status = nullptr;
do {
if (!server->IsRunning()) {
cntl->SetFailed(ELOGOFF, "Server is stopping");
Expand Down Expand Up @@ -703,9 +699,9 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
}
}

google::protobuf::Service* svc = NULL;
google::protobuf::MethodDescriptor* method = NULL;
if (NULL != server->options().baidu_master_service) {
google::protobuf::Service* svc = nullptr;
google::protobuf::MethodDescriptor* method = nullptr;
if (nullptr != server->options().baidu_master_service) {
if (socket->is_overcrowded() &&
!server->options().ignore_eovercrowded &&
!server->options().baidu_master_service->ignore_eovercrowded()) {
Expand All @@ -714,11 +710,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
break;
}
svc = server->options().baidu_master_service;
auto sampled_request = new (std::nothrow) SampledRequest;
if (NULL == sampled_request) {
cntl->SetFailed(ENOMEM, "Fail to get sampled_request");
break;
}
auto sampled_request = new SampledRequest;
sampled_request->meta.set_service_name(request_meta.service_name());
sampled_request->meta.set_method_name(request_meta.method_name());
cntl->reset_sampled_request(sampled_request);
Expand Down Expand Up @@ -753,7 +745,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
if (svc_name.find('.') == butil::StringPiece::npos) {
const Server::ServiceProperty* sp =
server_accessor.FindServicePropertyByName(svc_name);
if (NULL == sp) {
if (nullptr == sp) {
cntl->SetFailed(ENOSERVICE, "Fail to find service=%s",
request_meta.service_name().c_str());
break;
Expand All @@ -763,7 +755,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
const Server::MethodProperty* mp =
server_accessor.FindMethodPropertyByFullName(
svc_name, request_meta.method_name());
if (NULL == mp) {
if (nullptr == mp) {
cntl->SetFailed(ENOMETHOD, "Fail to find method=%s/%s",
request_meta.service_name().c_str(),
request_meta.method_name().c_str());
Expand All @@ -772,7 +764,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
BadMethodRequest breq;
BadMethodResponse bres;
breq.set_service_name(request_meta.service_name());
mp->service->CallMethod(mp->method, cntl.get(), &breq, &bres, NULL);
mp->service->CallMethod(mp->method, cntl.get(), &breq, &bres, nullptr);
break;
}
if (socket->is_overcrowded() &&
Expand Down Expand Up @@ -827,7 +819,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
// it into the checksum now when the client asked us to.
const butil::IOBuf* checksum_attachment =
cntl->request_checksum_attachment() ?
&cntl->request_attachment() : NULL;
&cntl->request_attachment() : nullptr;
if (!DeserializeRpcMessage(req_buf, *cntl, content_type,
compress_type, checksum_type,
messages->Request(),
Expand Down Expand Up @@ -898,7 +890,7 @@ bool VerifyRpcRequest(const InputMessageBase* msg_base) {
return false;
}
const Authenticator* auth = server->options().auth;
if (NULL == auth) {
if (nullptr == auth) {
// Fast pass (no authentication)
return true;
}
Expand Down Expand Up @@ -939,7 +931,7 @@ void ProcessRpcResponse(InputMessageBase* msg_base) {
}

const bthread_id_t cid = { static_cast<uint64_t>(meta.correlation_id()) };
Controller* cntl = NULL;
Controller* cntl = nullptr;

StreamId remote_stream_id = meta.has_stream_settings() ? meta.stream_settings().stream_id(): INVALID_STREAM_ID;

Expand Down Expand Up @@ -1016,7 +1008,7 @@ void ProcessRpcResponse(InputMessageBase* msg_base) {
// it into the checksum now when the server told us to.
const butil::IOBuf* checksum_attachment =
cntl->response_checksum_attachment() ?
&cntl->response_attachment() : NULL;
&cntl->response_attachment() : nullptr;
if (cntl->response()->GetDescriptor() == SerializedResponse::descriptor()) {
((SerializedResponse*)cntl->response())->
serialized_data().append(*res_buf_ptr);
Expand Down Expand Up @@ -1044,7 +1036,7 @@ void ProcessRpcResponse(InputMessageBase* msg_base) {
void SerializeRpcRequest(butil::IOBuf* request_buf, Controller* cntl,
const google::protobuf::Message* request) {
// Check sanity of request.
if (NULL == request) {
if (nullptr == request) {
return cntl->SetFailed(EREQUEST, "`request' is NULL");
}
if (request->GetDescriptor() == SerializedRequest::descriptor()) {
Expand All @@ -1059,7 +1051,7 @@ void SerializeRpcRequest(butil::IOBuf* request_buf, Controller* cntl,
ContentType content_type = cntl->request_content_type();
CompressType compress_type = cntl->request_compress_type();
ChecksumType checksum_type = cntl->request_checksum_type();
const butil::IOBuf* checksum_attachment = NULL;
const butil::IOBuf* checksum_attachment = nullptr;
if (cntl->request_checksum_attachment()) {
// Progressive reading (HTTP-only feature) hands the attachment to
// the user piece by piece as it arrives, so there's no single,
Expand Down Expand Up @@ -1108,7 +1100,7 @@ void PackRpcRequest(butil::IOBuf* req_buf,
if (cntl->request_checksum_attachment()) {
meta.set_checksum_with_attachment(true);
}
} else if (NULL != cntl->sampled_request()) {
} else if (nullptr != cntl->sampled_request()) {
// Replaying. Keep service-name as the one seen by server.
request_meta->set_service_name(cntl->sampled_request()->meta.service_name());
request_meta->set_method_name(cntl->sampled_request()->meta.method_name());
Expand Down
9 changes: 4 additions & 5 deletions src/brpc/policy/consistent_hashing_load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ size_t ConsistentHashingLoadBalancer::RemoveBatch(
bool use_set = true;
if (id_set.init(servers.size() * 2) == 0) {
for (size_t i = 0; i < servers.size(); ++i) {
if (id_set.insert(servers[i]) == NULL) {
if (id_set.insert(servers[i]) == nullptr) {
use_set = false;
break;
}
Expand All @@ -205,7 +205,7 @@ size_t ConsistentHashingLoadBalancer::RemoveBatch(
bg.clear();
for (size_t i = 0; i < fg.size(); ++i) {
const bool removed =
use_set ? (id_set.seek(fg[i].server_sock) != NULL)
use_set ? (id_set.seek(fg[i].server_sock) != nullptr)
: (std::find(servers.begin(), servers.end(),
fg[i].server_sock) != servers.end());
if (!removed) {
Expand Down Expand Up @@ -285,9 +285,8 @@ size_t ConsistentHashingLoadBalancer::RemoveServersInBatch(
}

LoadBalancer *ConsistentHashingLoadBalancer::New(const butil::StringPiece& params) const {
ConsistentHashingLoadBalancer* lb =
new (std::nothrow) ConsistentHashingLoadBalancer(_type);
if (lb && !lb->SetParameters(params)) {
ConsistentHashingLoadBalancer* lb = new ConsistentHashingLoadBalancer(_type);
if (!lb->SetParameters(params)) {
delete lb;
lb = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/policy/consul_naming_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int ConsulNamingService::GetServers(const char* service_name,

Controller cntl;
cntl.http_request().uri() = consul_url;
_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr);
if (cntl.Failed()) {
LOG(ERROR) << "Fail to access " << consul_url << ": "
<< cntl.ErrorText();
Expand Down
12 changes: 6 additions & 6 deletions src/brpc/policy/couchbase_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ ParseResult ParseCouchbaseMessage(butil::IOBuf* source, Socket* socket,
bool /*read_eof*/, const void* /*arg*/) {
while (1) {
const uint8_t* p_cbmagic = (const uint8_t*)source->fetch1();
if (NULL == p_cbmagic) {
if (nullptr == p_cbmagic) {
return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);
}
if (*p_cbmagic != (uint8_t)CB_MAGIC_RESPONSE) {
return MakeParseError(PARSE_ERROR_TRY_OTHERS);
}
char buf[24];
const uint8_t* p = (const uint8_t*)source->fetch(buf, sizeof(buf));
if (NULL == p) {
if (nullptr == p) {
return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);
}
const CouchbaseResponseHeader* header = (const CouchbaseResponseHeader*)p;
Expand All @@ -118,7 +118,7 @@ ParseResult ParseCouchbaseMessage(butil::IOBuf* source, Socket* socket,
}
MostCommonMessage* msg =
static_cast<MostCommonMessage*>(socket->parsing_context());
if (msg == NULL) {
if (msg == nullptr) {
msg = MostCommonMessage::Get();
socket->reset_parsing_context(msg);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ void ProcessCouchbaseResponse(InputMessageBase* msg_base) {
static_cast<MostCommonMessage*>(msg_base));

const bthread_id_t cid = msg->pi.id_wait;
Controller* cntl = NULL;
Controller* cntl = nullptr;
const int rc = bthread_id_lock(cid, (void**)&cntl);
if (rc != 0) {
LOG_IF(ERROR, rc != EINVAL && rc != EPERM)
Expand All @@ -171,7 +171,7 @@ void ProcessCouchbaseResponse(InputMessageBase* msg_base) {
span->set_start_parse_us(start_parse_us);
}
const int saved_error = cntl->ErrorCode();
if (cntl->response() == NULL) {
if (cntl->response() == nullptr) {
cntl->SetFailed(ERESPONSE, "response is NULL!");
} else if (cntl->response()->GetDescriptor() !=
CouchbaseOperations::CouchbaseResponse::descriptor()) {
Expand All @@ -195,7 +195,7 @@ void ProcessCouchbaseResponse(InputMessageBase* msg_base) {

void SerializeCouchbaseRequest(butil::IOBuf* buf, Controller* cntl,
const google::protobuf::Message* request) {
if (request == NULL) {
if (request == nullptr) {
return cntl->SetFailed(EREQUEST, "request is NULL");
}
if (request->GetDescriptor() !=
Expand Down
4 changes: 2 additions & 2 deletions src/brpc/policy/crc32c_checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ uint32_t ExtendCrc32c(uint32_t crc, const butil::IOBuf& buf) {
}

// Computes the crc32c over `in.buf', and over `in.attachment' as well when
// the caller opted in (ChecksumIn::attachment != NULL).
// the caller opted in (ChecksumIn::attachment != nullptr).
uint32_t ComputeCrc32c(const ChecksumIn& in) {
uint32_t crc = ExtendCrc32c(0, *in.buf);
if (in.attachment != NULL) {
if (in.attachment != nullptr) {
crc = ExtendCrc32c(crc, *in.attachment);
}
return crc;
Expand Down
20 changes: 10 additions & 10 deletions src/brpc/policy/dh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace brpc {
namespace policy {

void DHWrapper::clear() {
if (_pdh != NULL) {
if (_pdh != nullptr) {
DH_free(_pdh);
_pdh = NULL;
_pdh = nullptr;
}
}

Expand All @@ -37,8 +37,8 @@ int DHWrapper::initialize(bool ensure_128bytes_public_key) {
return -1;
}
if (ensure_128bytes_public_key) {
const BIGNUM* pub_key = NULL;
DH_get0_key(_pdh, &pub_key, NULL);
const BIGNUM* pub_key = nullptr;
DH_get0_key(_pdh, &pub_key, nullptr);
int key_size = BN_num_bytes(pub_key);
if (key_size != 128) {
RPC_VLOG << "regenerate 128B key, current=" << key_size;
Expand All @@ -52,8 +52,8 @@ int DHWrapper::initialize(bool ensure_128bytes_public_key) {
}

int DHWrapper::copy_public_key(char* pkey, int* pkey_size) const {
const BIGNUM* pub_key = NULL;
DH_get0_key(_pdh, &pub_key, NULL);
const BIGNUM* pub_key = nullptr;
DH_get0_key(_pdh, &pub_key, nullptr);
// copy public key to bytes.
// sometimes, the key_size is 127, seems ok.
int key_size = BN_num_bytes(pub_key);
Expand All @@ -75,7 +75,7 @@ int DHWrapper::copy_public_key(char* pkey, int* pkey_size) const {
int DHWrapper::copy_shared_key(const void* ppkey, int ppkey_size,
void* skey, int* skey_size) const {
BIGNUM* ppk = BN_bin2bn((const unsigned char*)ppkey, ppkey_size, 0);
if (ppk == NULL) {
if (ppk == nullptr) {
LOG(ERROR) << "Fail to BN_bin2bn";
return -1;
}
Expand All @@ -91,13 +91,13 @@ int DHWrapper::copy_shared_key(const void* ppkey, int ppkey_size,
}

int DHWrapper::do_initialize() {
BIGNUM* p = get_rfc2409_prime_1024(NULL);
BIGNUM* p = get_rfc2409_prime_1024(nullptr);
if (!p) {
return -1;
}
// See RFC 2409, Section 6 "Oakley Groups"
// for the reason why 2 is used as generator.
BIGNUM* g = NULL;
BIGNUM* g = nullptr;
BN_dec2bn(&g, "2");
if (!g) {
BN_free(p);
Expand All @@ -109,7 +109,7 @@ int DHWrapper::do_initialize() {
BN_free(g);
return -1;
}
DH_set0_pqg(_pdh, p, NULL, g);
DH_set0_pqg(_pdh, p, nullptr, g);

// Generate private and public key
if (!DH_generate_key(_pdh)) {
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/policy/dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace policy {
// Diffie-Hellman key exchange
class DHWrapper {
public:
DHWrapper() : _pdh(NULL) {}
DHWrapper() : _pdh(nullptr) {}
~DHWrapper() { clear(); }

// initialize dh, generate the public and private key.
Expand Down
Loading
Loading