Refactor NULL with nullptr in example (#3466)
This commit is contained in:
@@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -75,7 +75,7 @@ int main(int argc, char* argv[]) {
|
||||
// Send a request and wait for the response every 1 second.
|
||||
int log_id = 0;
|
||||
while (!brpc::IsAskedToQuit()) {
|
||||
// Since we are sending asynchronous RPC (`done' is not NULL),
|
||||
// Since we are sending asynchronous RPC (`done' is not nullptr),
|
||||
// these objects MUST remain valid until `done' is called.
|
||||
// As a result, we allocate these objects on heap
|
||||
example::EchoResponse* response = new example::EchoResponse();
|
||||
|
||||
@@ -78,8 +78,8 @@ public:
|
||||
// at this time res is already sent to client, but cntl/req/res is not destructed
|
||||
std::string req_str;
|
||||
std::string res_str;
|
||||
json2pb::ProtoMessageToJson(*req, &req_str, NULL);
|
||||
json2pb::ProtoMessageToJson(*res, &res_str, NULL);
|
||||
json2pb::ProtoMessageToJson(*req, &req_str, nullptr);
|
||||
json2pb::ProtoMessageToJson(*res, &res_str, nullptr);
|
||||
LOG(INFO) << "req:" << req_str
|
||||
<< " res:" << res_str;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ void RunCase(test::ControlService_Stub &cntl_stub,
|
||||
test::NotifyResponse cntl_rsp;
|
||||
brpc::Controller cntl;
|
||||
cntl_req.set_message("StartCase");
|
||||
cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, NULL);
|
||||
cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, nullptr);
|
||||
CHECK(!cntl.Failed()) << "control failed";
|
||||
|
||||
TestCaseContext context(test_case);
|
||||
@@ -208,7 +208,7 @@ void RunCase(test::ControlService_Stub &cntl_stub,
|
||||
::sleep(FLAGS_case_interval);
|
||||
cntl.Reset();
|
||||
cntl_req.set_message("StopCase");
|
||||
cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, NULL);
|
||||
cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, nullptr);
|
||||
CHECK(!cntl.Failed()) << "control failed";
|
||||
LOG(INFO) << "Case `" << test_case.case_name() << "' finshed:";
|
||||
}
|
||||
@@ -237,7 +237,7 @@ int main(int argc, char* argv[]) {
|
||||
test::NotifyRequest cntl_req;
|
||||
test::NotifyResponse cntl_rsp;
|
||||
cntl_req.set_message("ResetCaseSet");
|
||||
cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, NULL);
|
||||
cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, nullptr);
|
||||
CHECK(!cntl.Failed()) << "Cntl Failed";
|
||||
for (int i = 0; i < case_set.test_case_size(); ++i) {
|
||||
RunCase(cntl_stub, case_set.test_case(i));
|
||||
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
brpc::SERVER_OWNS_SERVICE) != 0) {
|
||||
LOG(FATAL) << "Fail to add service";
|
||||
}
|
||||
g_timer_thread.start(NULL);
|
||||
g_timer_thread.start(nullptr);
|
||||
}
|
||||
virtual ~ControlServiceImpl() {
|
||||
_echo_service->StopTestCase();
|
||||
@@ -284,7 +284,7 @@ int main(int argc, char* argv[]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (server.Start(FLAGS_cntl_port, NULL) != 0) {
|
||||
if (server.Start(FLAGS_cntl_port, nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to start EchoServer";
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -68,9 +68,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
request.set_index(++counter);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
LOG(INFO) << "Received response[index=" << response.index()
|
||||
<< "] from " << cntl.remote_side()
|
||||
|
||||
@@ -40,7 +40,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_BAIDU_STD;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -73,9 +73,9 @@ int main(int argc, char* argv[]) {
|
||||
// being serialized into protobuf messages.
|
||||
cntl.request_attachment().append(FLAGS_attachment);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
LOG(INFO) << "Received response from " << cntl.remote_side()
|
||||
<< " to " << cntl.local_side()
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_BAIDU_STD;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
call_cntl.set_request_compress_type(cntl->request_compress_type());
|
||||
call_cntl.reset_sampled_request(cntl->release_sampled_request());
|
||||
// It is ok to use request and response for sync rpc.
|
||||
channel.CallMethod(NULL, &call_cntl, request, response, NULL);
|
||||
channel.CallMethod(nullptr, &call_cntl, request, response, nullptr);
|
||||
(*cntl->response_user_fields())["x-bd-proxy-error-code"] =
|
||||
butil::IntToString(call_cntl.ErrorCode());
|
||||
if (call_cntl.Failed()) {
|
||||
|
||||
@@ -63,9 +63,9 @@ static void* sender(void* arg) {
|
||||
// being serialized into protobuf messages.
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
} else {
|
||||
@@ -79,7 +79,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -90,7 +90,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -120,7 +120,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -144,9 +144,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
|
||||
@@ -70,9 +70,9 @@ void* sender(void* arg) {
|
||||
// being serialized into protobuf messages.
|
||||
cntl.request_attachment().append(FLAGS_attachment);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
//LOG_EVERY_SECOND(WARNING) << "Fail to send EchoRequest, " << cntl.ErrorText();
|
||||
} else {
|
||||
@@ -82,7 +82,7 @@ void* sender(void* arg) {
|
||||
bthread_usleep(FLAGS_sleep_ms * 1000L);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -99,7 +99,7 @@ int main(int argc, char* argv[]) {
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
options.max_retry = FLAGS_max_retry;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
// options, see `brpc/channel.h'.
|
||||
if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize channel";
|
||||
@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -140,9 +140,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
cntl2.set_timeout_ms(FLAGS_timeout_ms);
|
||||
cntl2.set_max_retry(FLAGS_max_retry);
|
||||
stub.Echo(&cntl2, &request2, &response2, NULL);
|
||||
stub.Echo(&cntl2, &request2, &response2, nullptr);
|
||||
if (cntl2.Failed()) {
|
||||
CLOGE(&cntl2) << "Fail to send EchoRequest, " << cntl2.ErrorText();
|
||||
cntl->SetFailed(cntl2.ErrorCode(), "%s", cntl2.ErrorText().c_str());
|
||||
@@ -95,7 +95,7 @@ int main(int argc, char* argv[]) {
|
||||
coption.protocol = brpc::PROTOCOL_HTTP;
|
||||
}
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
// options, see `brpc/channel.h'.
|
||||
if (FLAGS_server.empty()) {
|
||||
if (channel.Init("localhost", FLAGS_port, &coption) != 0) {
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
brpc::ClosureGuard done_guard(done);
|
||||
EchoService_Stub stub(&_channel);
|
||||
brpc::Controller cntl;
|
||||
stub.Echo(&cntl, request, response, NULL);
|
||||
stub.Echo(&cntl, request, response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
response->set_message(cntl.ErrorText());
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ void* thread_worker(void* arg) {
|
||||
if (!auth_result.success) {
|
||||
std::cout << RED << "Thread " << args->thread_id << ": Auth failed - "
|
||||
<< auth_result.error_message << RESET << std::endl;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// // Select bucket
|
||||
@@ -197,7 +197,7 @@ void* thread_worker(void* arg) {
|
||||
// std::cout << RED << "Thread " << args->thread_id
|
||||
// << ": Bucket selection failed - " << bucket_result.error_message
|
||||
// << RESET << std::endl;
|
||||
// return NULL;
|
||||
// return nullptr;
|
||||
// }
|
||||
|
||||
std::cout << GREEN << "Thread " << args->thread_id << " connected to bucket "
|
||||
@@ -228,7 +228,7 @@ void* thread_worker(void* arg) {
|
||||
<< " operations successful, " << failed << " failed" << RESET
|
||||
<< std::endl;
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* shared_object_thread_worker(void *arg){
|
||||
@@ -246,7 +246,7 @@ void* shared_object_thread_worker(void *arg){
|
||||
// Small delay between operations
|
||||
bthread_usleep(10000); // 10ms
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Print simple statistics
|
||||
@@ -319,7 +319,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// Start all threads
|
||||
for (int i = 0; i < NUM_THREADS; ++i) {
|
||||
if (bthread_start_background(&threads[i], NULL, thread_worker, &args[i]) !=
|
||||
if (bthread_start_background(&threads[i], nullptr, thread_worker, &args[i]) !=
|
||||
0) {
|
||||
std::cout << RED << "Failed to create thread " << i << RESET << std::endl;
|
||||
return -1;
|
||||
@@ -332,7 +332,7 @@ int main(int argc, char* argv[]) {
|
||||
std::cout << YELLOW << "Waiting for all threads to complete..." << RESET
|
||||
<< std::endl;
|
||||
for (int i = 0; i < NUM_THREADS; ++i) {
|
||||
bthread_join(threads[i], NULL);
|
||||
bthread_join(threads[i], nullptr);
|
||||
}
|
||||
|
||||
std::cout << GREEN << "All threads completed!" << RESET << std::endl;
|
||||
@@ -357,14 +357,14 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
for(int i = 0; i < NUM_THREADS; ++i){
|
||||
if (bthread_start_background(&threads[i], NULL, shared_object_thread_worker, &args[i]) !=
|
||||
if (bthread_start_background(&threads[i], nullptr, shared_object_thread_worker, &args[i]) !=
|
||||
0) {
|
||||
std::cout << RED << "Failed to create shared object thread " << i << RESET << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < NUM_THREADS; ++i){
|
||||
bthread_join(threads[i], NULL);
|
||||
bthread_join(threads[i], nullptr);
|
||||
}
|
||||
std::cout << GREEN << "All shared object threads completed!" << RESET << std::endl;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ int main() {
|
||||
brpc::CouchbaseOperations::CouchbaseResponse res;
|
||||
uint64_t cas;
|
||||
req.authenticateRequest("Administrator", "password");
|
||||
channel.CallMethod(NULL, &cntl, &req, &res, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &req, &res, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Unable to authenticate: Something went wrong"
|
||||
<< cntl.ErrorText();
|
||||
@@ -63,7 +63,7 @@ int main() {
|
||||
req.Clear();
|
||||
res.Clear();
|
||||
req.selectBucketRequest("testing");
|
||||
channel.CallMethod(NULL, &cntl, &req, &res, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &req, &res, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Unable to select bucket: Something went wrong"
|
||||
<< cntl.ErrorText();
|
||||
@@ -92,7 +92,7 @@ int main() {
|
||||
"sample_key",
|
||||
R"({"name": "John Doe", "age": 30, "email": "john@example.com"})",
|
||||
0 /*flags*/, 0 /*exptime*/, 0 /*cas*/);
|
||||
channel.CallMethod(NULL, &cntl, &req, &res, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &req, &res, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Unable to add key-value: Something went wrong"
|
||||
<< cntl.ErrorText();
|
||||
@@ -118,7 +118,7 @@ int main() {
|
||||
req.Clear();
|
||||
res.Clear();
|
||||
req.getRequest("sample_key");
|
||||
channel.CallMethod(NULL, &cntl, &req, &res, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &req, &res, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Unable to get value for key: Something went wrong"
|
||||
<< cntl.ErrorText();
|
||||
@@ -147,7 +147,7 @@ int main() {
|
||||
req.Clear();
|
||||
res.Clear();
|
||||
req.deleteRequest("sample_key");
|
||||
channel.CallMethod(NULL, &cntl, &req, &res, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &req, &res, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Unable to delete key-value: Something went wrong"
|
||||
<< cntl.ErrorText();
|
||||
|
||||
@@ -53,7 +53,7 @@ static void* sender(void* arg) {
|
||||
// a stub Service wrapping it. stub can be shared by all threads as well.
|
||||
example::EchoService_Stub stub(static_cast<google::protobuf::RpcChannel*>(arg));
|
||||
|
||||
SenderInfo* info = NULL;
|
||||
SenderInfo* info = nullptr;
|
||||
{
|
||||
BAIDU_SCOPED_LOCK(g_latency_mutex);
|
||||
g_sender_info.push_back(SenderInfo());
|
||||
@@ -76,9 +76,9 @@ static void* sender(void* arg) {
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
info->latency_sum += cntl.latency_us();
|
||||
++info->nsuccess;
|
||||
@@ -92,7 +92,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class MyPartitionParser : public brpc::PartitionParser {
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
LOG(ERROR) << "Invalid tag=" << tag;
|
||||
return false;
|
||||
}
|
||||
char* endptr = NULL;
|
||||
char* endptr = nullptr;
|
||||
out->index = strtol(tag.c_str(), &endptr, 10);
|
||||
if (endptr != tag.data() + pos) {
|
||||
LOG(ERROR) << "Invalid index=" << butil::StringPiece(tag.data(), pos);
|
||||
@@ -156,7 +156,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -203,9 +203,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
|
||||
butil::StringSplitter sp(FLAGS_sleep_us.c_str(), ',');
|
||||
std::vector<int64_t> sleep_list;
|
||||
for (; sp; ++sp) {
|
||||
sleep_list.push_back(strtoll(sp.field(), NULL, 10));
|
||||
sleep_list.push_back(strtoll(sp.field(), nullptr, 10));
|
||||
}
|
||||
if (sleep_list.empty()) {
|
||||
sleep_list.push_back(0);
|
||||
|
||||
@@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -77,9 +77,9 @@ int main(int argc, char* argv[]) {
|
||||
cntl.set_request_checksum_type(brpc::CHECKSUM_TYPE_CRC32C);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
LOG(INFO) << "Received response from " << cntl.remote_side()
|
||||
<< " to " << cntl.local_side()
|
||||
|
||||
@@ -90,8 +90,8 @@ public:
|
||||
// at this time res is already sent to client, but cntl/req/res is not destructed
|
||||
std::string req_str;
|
||||
std::string res_str;
|
||||
json2pb::ProtoMessageToJson(*req, &req_str, NULL);
|
||||
json2pb::ProtoMessageToJson(*res, &res_str, NULL);
|
||||
json2pb::ProtoMessageToJson(*req, &req_str, nullptr);
|
||||
json2pb::ProtoMessageToJson(*res, &res_str, nullptr);
|
||||
LOG(INFO) << "req:" << req_str
|
||||
<< " res:" << res_str;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
@@ -68,9 +68,9 @@ int main(int argc, char* argv[]) {
|
||||
if (FLAGS_gzip) {
|
||||
cntl.set_request_compress_type(brpc::COMPRESS_TYPE_GZIP);
|
||||
}
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.SayHello(&cntl, &request, &response, NULL);
|
||||
stub.SayHello(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
LOG(INFO) << "Received response from " << cntl.remote_side()
|
||||
<< " to " << cntl.local_side()
|
||||
|
||||
@@ -54,9 +54,9 @@ static void* sender(void* arg) {
|
||||
cntl.request_attachment().append(FLAGS_data);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
channel->CallMethod(NULL, &cntl, NULL, NULL, NULL);
|
||||
channel->CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(100000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -83,7 +83,7 @@ int main(int argc, char* argv[]) {
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
// options, see `brpc/channel.h'.
|
||||
if (channel.Init(FLAGS_url.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize channel";
|
||||
@@ -95,7 +95,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -125,9 +125,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "benchmark_http is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
options.max_retry = FLAGS_max_retry;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
// options, see `brpc/channel.h'.
|
||||
if (channel.Init(url, FLAGS_load_balancer.c_str(), &options) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize channel";
|
||||
@@ -71,9 +71,9 @@ int main(int argc, char* argv[]) {
|
||||
cntl.request_attachment().append(FLAGS_d);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
std::cerr << cntl.ErrorText() << std::endl;
|
||||
return -1;
|
||||
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
// at this time res is already sent to client, but cntl/req/res is not destructed
|
||||
std::string req_str;
|
||||
std::string res_str;
|
||||
json2pb::ProtoMessageToJson(*req, &req_str, NULL);
|
||||
json2pb::ProtoMessageToJson(*res, &res_str, NULL);
|
||||
json2pb::ProtoMessageToJson(*req, &req_str, nullptr);
|
||||
json2pb::ProtoMessageToJson(*res, &res_str, nullptr);
|
||||
LOG(INFO) << "req:" << req_str
|
||||
<< " res:" << res_str;
|
||||
}
|
||||
@@ -93,9 +93,9 @@ public:
|
||||
|
||||
static void* SendLargeFile(void* raw_args) {
|
||||
std::unique_ptr<Args> args(static_cast<Args*>(raw_args));
|
||||
if (args->pa == NULL) {
|
||||
if (args->pa == nullptr) {
|
||||
LOG(ERROR) << "ProgressiveAttachment is NULL";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
char buf[16];
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
// sleep a while to send another part.
|
||||
bthread_usleep(10000);
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void default_method(google::protobuf::RpcController* cntl_base,
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
std::unique_ptr<Args> args(new Args);
|
||||
args->pa = cntl->CreateProgressiveAttachment();
|
||||
bthread_t th;
|
||||
bthread_start_background(&th, NULL, SendLargeFile, args.release());
|
||||
bthread_start_background(&th, nullptr, SendLargeFile, args.release());
|
||||
} else {
|
||||
cntl->response_attachment().append("Getting file: ");
|
||||
cntl->response_attachment().append(filename);
|
||||
@@ -183,9 +183,9 @@ public:
|
||||
|
||||
static void* Predict(void* raw_args) {
|
||||
std::unique_ptr<PredictJobArgs> args(static_cast<PredictJobArgs*>(raw_args));
|
||||
if (args->pa == NULL) {
|
||||
if (args->pa == nullptr) {
|
||||
LOG(ERROR) << "ProgressiveAttachment is NULL";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
char buf[48];
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
// sleep a while to send another part.
|
||||
bthread_usleep(10000 * 10);
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void stream(google::protobuf::RpcController* cntl_base,
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
args->pa = cntl->CreateProgressiveAttachment();
|
||||
args->input_ids = {101, 102};
|
||||
bthread_t th;
|
||||
bthread_start_background(&th, NULL, Predict, args.release());
|
||||
bthread_start_background(&th, nullptr, Predict, args.release());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -67,18 +67,18 @@ static void* sender(void* arg) {
|
||||
brpc::MemcacheResponse response;
|
||||
brpc::Controller cntl;
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
channel->CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel->CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
const int64_t elp = cntl.latency_us();
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
for (int i = 0; i < FLAGS_batch; ++i) {
|
||||
uint32_t flags;
|
||||
if (!response.PopGet(&value, &flags, NULL)) {
|
||||
if (!response.PopGet(&value, &flags, nullptr)) {
|
||||
LOG(INFO) << "Fail to GET the key, " << response.LastError();
|
||||
brpc::AskToQuit();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
CHECK(flags == 0xdeadbeef + base_index + i)
|
||||
<< "flags=" << flags;
|
||||
@@ -96,7 +96,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -110,7 +110,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_MEMCACHE;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -141,13 +141,13 @@ int main(int argc, char* argv[]) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to access memcache, " << cntl.ErrorText();
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < FLAGS_batch * FLAGS_thread_num; ++i) {
|
||||
if (!response.PopSet(NULL)) {
|
||||
if (!response.PopSet(nullptr)) {
|
||||
LOG(ERROR) << "Fail to SET memcache, i=" << i
|
||||
<< ", " << response.LastError();
|
||||
return -1;
|
||||
@@ -166,7 +166,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -191,9 +191,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "memcache_client is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
if (options.auth) {
|
||||
|
||||
@@ -64,9 +64,9 @@ static void* sender(void* arg) {
|
||||
// being serialized into protobuf messages.
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
} else {
|
||||
@@ -80,7 +80,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -91,7 +91,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
if (FLAGS_enable_ssl) {
|
||||
options.mutable_ssl_options();
|
||||
@@ -124,7 +124,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -149,9 +149,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,9 +68,9 @@ static void* sender(void* arg) {
|
||||
// being serialized into protobuf messages.
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
CHECK(response.value() == request.value() + 1);
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
@@ -86,7 +86,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -97,7 +97,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.backup_request_ms = FLAGS_backup_timeout_ms;
|
||||
options.protocol = FLAGS_protocol;
|
||||
@@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -147,9 +147,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ int main(int argc, char* argv[]) {
|
||||
butil::StringSplitter sp(FLAGS_sleep_us.c_str(), ',');
|
||||
std::vector<int64_t> sleep_list;
|
||||
for (; sp; ++sp) {
|
||||
sleep_list.push_back(strtoll(sp.field(), NULL, 10));
|
||||
sleep_list.push_back(strtoll(sp.field(), nullptr, 10));
|
||||
}
|
||||
if (sleep_list.empty()) {
|
||||
sleep_list.push_back(0);
|
||||
|
||||
@@ -54,7 +54,7 @@ static bool access_mysql(brpc::Channel& channel, const char* command) {
|
||||
}
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
std::cout << response << std::endl;
|
||||
} else {
|
||||
@@ -93,7 +93,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_MYSQL;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -127,7 +127,7 @@ int main(int argc, char* argv[]) {
|
||||
char prompt[128];
|
||||
snprintf(prompt, sizeof(prompt), "mysql %s> ", FLAGS_server.c_str());
|
||||
std::unique_ptr<char, Freer> command(readline(prompt));
|
||||
if (command == NULL || *command == '\0') {
|
||||
if (command == nullptr || *command == '\0') {
|
||||
if (g_canceled) {
|
||||
// No input after the prompt and user pressed Ctrl-C,
|
||||
// quit the CLI.
|
||||
|
||||
@@ -81,13 +81,13 @@ static void* sender(void* void_args) {
|
||||
brpc::MysqlRequest request;
|
||||
if (!request.Query(command.str())) {
|
||||
LOG(ERROR) << "Fail to execute command";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
while (!brpc::IsAskedToQuit()) {
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
args->mysql_channel->CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
args->mysql_channel->CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
const int64_t elp = cntl.latency_us();
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << elp;
|
||||
@@ -109,7 +109,7 @@ static void* sender(void* void_args) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -120,7 +120,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_MYSQL;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -146,7 +146,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
std::cout << response << std::endl;
|
||||
} else {
|
||||
@@ -164,7 +164,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
std::cout << response << std::endl;
|
||||
} else {
|
||||
@@ -183,7 +183,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << cntl.ErrorText();
|
||||
return -1;
|
||||
@@ -210,12 +210,12 @@ int main(int argc, char* argv[]) {
|
||||
args[i].base_index = i;
|
||||
args[i].mysql_channel = &channel;
|
||||
if (!FLAGS_use_bthread) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &args[i]) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (bthread_start_background(&bids[i], NULL, sender, &args[i]) != 0) {
|
||||
if (bthread_start_background(&bids[i], nullptr, sender, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -232,9 +232,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "mysql_client is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,69 +60,69 @@ static void* access_mysql(void* void_args) {
|
||||
brpc::MysqlRequest request(stmt);
|
||||
for (size_t i = 1; i < commands.size(); i += 2) {
|
||||
if (commands[i] == "int8") {
|
||||
int8_t val = strtol(commands[i + 1].c_str(), NULL, 10);
|
||||
int8_t val = strtol(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add int8 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "uint8") {
|
||||
uint8_t val = strtoul(commands[i + 1].c_str(), NULL, 10);
|
||||
uint8_t val = strtoul(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add uint8 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "int16") {
|
||||
int16_t val = strtol(commands[i + 1].c_str(), NULL, 10);
|
||||
int16_t val = strtol(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add uint16 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "uint16") {
|
||||
uint16_t val = strtoul(commands[i + 1].c_str(), NULL, 10);
|
||||
uint16_t val = strtoul(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add uint16 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "int32") {
|
||||
int32_t val = strtol(commands[i + 1].c_str(), NULL, 10);
|
||||
int32_t val = strtol(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add int32 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "uint32") {
|
||||
uint32_t val = strtoul(commands[i + 1].c_str(), NULL, 10);
|
||||
uint32_t val = strtoul(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add uint32 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "int64") {
|
||||
int64_t val = strtol(commands[i + 1].c_str(), NULL, 10);
|
||||
int64_t val = strtol(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add int64 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "uint64") {
|
||||
uint64_t val = strtoul(commands[i + 1].c_str(), NULL, 10);
|
||||
uint64_t val = strtoul(commands[i + 1].c_str(), nullptr, 10);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add uint64 param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "float") {
|
||||
float val = strtof(commands[i + 1].c_str(), NULL);
|
||||
float val = strtof(commands[i + 1].c_str(), nullptr);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add float param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "double") {
|
||||
double val = strtod(commands[i + 1].c_str(), NULL);
|
||||
double val = strtod(commands[i + 1].c_str(), nullptr);
|
||||
if (!request.AddParam(val)) {
|
||||
LOG(ERROR) << "Fail to add double param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (commands[i] == "string") {
|
||||
if (!request.AddParam(commands[i + 1])) {
|
||||
LOG(ERROR) << "Fail to add string param";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "Wrong param type " << commands[i];
|
||||
@@ -131,16 +131,16 @@ static void* access_mysql(void* void_args) {
|
||||
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel->CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel->CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to access mysql, " << cntl.ErrorText();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::cout << response << std::endl;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -151,7 +151,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_MYSQL;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -174,7 +174,7 @@ int main(int argc, char* argv[]) {
|
||||
commands.push_back(argv[i]);
|
||||
}
|
||||
auto stmt(brpc::NewMysqlStatement(channel, commands[0]));
|
||||
if (stmt == NULL) {
|
||||
if (stmt == nullptr) {
|
||||
LOG(ERROR) << "Fail to create mysql statement";
|
||||
return -1;
|
||||
}
|
||||
@@ -188,14 +188,14 @@ int main(int argc, char* argv[]) {
|
||||
args[i].mysql_channel = &channel;
|
||||
args[i].mysql_stmt = stmt.get();
|
||||
args[i].commands = commands;
|
||||
if (bthread_start_background(&bids[i], NULL, access_mysql, &args[i]) != 0) {
|
||||
if (bthread_start_background(&bids[i], nullptr, access_mysql, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ static bool access_mysql(brpc::Channel& channel, const std::vector<std::string>&
|
||||
options.readonly = FLAGS_readonly;
|
||||
options.isolation_level = brpc::MysqlIsolationLevel(FLAGS_isolation_level);
|
||||
auto tx(brpc::NewMysqlTransaction(channel, options));
|
||||
if (tx == NULL) {
|
||||
if (tx == nullptr) {
|
||||
LOG(ERROR) << "Fail to create transaction";
|
||||
return false;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ static bool access_mysql(brpc::Channel& channel, const std::vector<std::string>&
|
||||
}
|
||||
brpc::MysqlResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to access mysql, " << cntl.ErrorText();
|
||||
tx->rollback();
|
||||
@@ -89,7 +89,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_MYSQL;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
|
||||
@@ -88,7 +88,7 @@ static void* sender(void* void_args) {
|
||||
CHECK_EQ(mysql_affected_rows(args->mysql_conn), 1);
|
||||
} else if (FLAGS_op_type == 1) {
|
||||
MYSQL_RES* res = mysql_store_result(args->mysql_conn);
|
||||
if (res == NULL) {
|
||||
if (res == nullptr) {
|
||||
LOG(INFO) << "not found";
|
||||
} else {
|
||||
CHECK_EQ(mysql_num_rows(res), 1);
|
||||
@@ -115,7 +115,7 @@ static void* sender(void* void_args) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -126,14 +126,14 @@ int main(int argc, char* argv[]) {
|
||||
brpc::StartDummyServerAt(FLAGS_dummy_port);
|
||||
}
|
||||
|
||||
MYSQL* conn = mysql_init(NULL);
|
||||
MYSQL* conn = mysql_init(nullptr);
|
||||
if (!mysql_real_connect(conn,
|
||||
FLAGS_server.c_str(),
|
||||
FLAGS_user.c_str(),
|
||||
FLAGS_password.c_str(),
|
||||
FLAGS_schema.c_str(),
|
||||
FLAGS_port,
|
||||
NULL,
|
||||
nullptr,
|
||||
0)) {
|
||||
LOG(ERROR) << mysql_error(conn);
|
||||
return -1;
|
||||
@@ -197,14 +197,14 @@ int main(int argc, char* argv[]) {
|
||||
std::vector<SenderArgs> args;
|
||||
args.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
MYSQL* conn = mysql_init(NULL);
|
||||
MYSQL* conn = mysql_init(nullptr);
|
||||
if (!mysql_real_connect(conn,
|
||||
FLAGS_server.c_str(),
|
||||
FLAGS_user.c_str(),
|
||||
FLAGS_password.c_str(),
|
||||
FLAGS_schema.c_str(),
|
||||
FLAGS_port,
|
||||
NULL,
|
||||
nullptr,
|
||||
0)) {
|
||||
LOG(ERROR) << mysql_error(conn);
|
||||
return -1;
|
||||
@@ -212,12 +212,12 @@ int main(int argc, char* argv[]) {
|
||||
args[i].base_index = i;
|
||||
args[i].mysql_conn = conn;
|
||||
if (!FLAGS_use_bthread) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &args[i]) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (bthread_start_background(&bids[i], NULL, sender, &args[i]) != 0) {
|
||||
if (bthread_start_background(&bids[i], nullptr, sender, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -234,9 +234,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "mysql_client is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_NSHEAD;
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
@@ -63,9 +63,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
cntl.set_log_id(log_id ++); // set by user
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to send nshead request, " << cntl.ErrorText();
|
||||
sleep(1); // Remove this sleep in production code.
|
||||
|
||||
@@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_NSHEAD;
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
@@ -63,9 +63,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
cntl.set_log_id(log_id ++); // set by user
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to send nshead request, " << cntl.ErrorText();
|
||||
sleep(1); // Remove this sleep in production code.
|
||||
|
||||
@@ -46,7 +46,7 @@ std::string g_request;
|
||||
std::string g_attachment;
|
||||
bvar::LatencyRecorder g_latency_recorder("client");
|
||||
bvar::Adder<int> g_error_count("client_error_count");
|
||||
bvar::LatencyRecorder* g_sub_channel_latency = NULL;
|
||||
bvar::LatencyRecorder* g_sub_channel_latency = nullptr;
|
||||
|
||||
static void* sender(void* arg) {
|
||||
// Normally, you should not call a Channel directly, but instead construct
|
||||
@@ -68,9 +68,9 @@ static void* sender(void* arg) {
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
for (int i = 0; i < cntl.sub_count(); ++i) {
|
||||
@@ -89,7 +89,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
|
||||
// For brpc >= 1.0.155.31351, a sub channel can be added into
|
||||
// a ParallelChannel more than once.
|
||||
brpc::Channel* sub_channel = new brpc::Channel;
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
// options, see `brpc/channel.h'.
|
||||
if (sub_channel->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &sub_options) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize sub_channel";
|
||||
@@ -125,7 +125,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
for (int i = 0; i < FLAGS_channel_num; ++i) {
|
||||
if (channel.AddChannel(sub_channel, brpc::OWNS_CHANNEL,
|
||||
NULL, NULL) != 0) {
|
||||
nullptr, nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to AddChannel, i=" << i;
|
||||
return -1;
|
||||
}
|
||||
@@ -133,14 +133,14 @@ int main(int argc, char* argv[]) {
|
||||
} else {
|
||||
for (int i = 0; i < FLAGS_channel_num; ++i) {
|
||||
brpc::Channel* sub_channel = new brpc::Channel;
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
// options, see `brpc/channel.h'.
|
||||
if (sub_channel->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &sub_options) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize sub_channel[" << i << "]";
|
||||
return -1;
|
||||
}
|
||||
if (channel.AddChannel(sub_channel, brpc::OWNS_CHANNEL,
|
||||
NULL, NULL) != 0) {
|
||||
nullptr, nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to AddChannel, i=" << i;
|
||||
return -1;
|
||||
}
|
||||
@@ -173,7 +173,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -204,9 +204,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ static void* sender(void* arg) {
|
||||
// a stub Service wrapping it. stub can be shared by all threads as well.
|
||||
example::EchoService_Stub stub(static_cast<google::protobuf::RpcChannel*>(arg));
|
||||
|
||||
SenderInfo* info = NULL;
|
||||
SenderInfo* info = nullptr;
|
||||
{
|
||||
BAIDU_SCOPED_LOCK(g_latency_mutex);
|
||||
g_sender_info.push_back(SenderInfo());
|
||||
@@ -77,9 +77,9 @@ static void* sender(void* arg) {
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
info->latency_sum += cntl.latency_us();
|
||||
++info->nsuccess;
|
||||
@@ -93,7 +93,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class MyPartitionParser : public brpc::PartitionParser {
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
LOG(ERROR) << "Invalid tag=`" << tag << '\'';
|
||||
return false;
|
||||
}
|
||||
char* endptr = NULL;
|
||||
char* endptr = nullptr;
|
||||
out->index = strtol(tag.c_str(), &endptr, 10);
|
||||
if (endptr != tag.data() + pos) {
|
||||
LOG(ERROR) << "Invalid index=" << butil::StringPiece(tag.data(), pos);
|
||||
@@ -158,7 +158,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -205,9 +205,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
|
||||
butil::StringSplitter sp(FLAGS_sleep_us.c_str(), ',');
|
||||
std::vector<int64_t> sleep_list;
|
||||
for (; sp; ++sp) {
|
||||
sleep_list.push_back(strtoll(sp.field(), NULL, 10));
|
||||
sleep_list.push_back(strtoll(sp.field(), nullptr, 10));
|
||||
}
|
||||
if (sleep_list.empty()) {
|
||||
sleep_list.push_back(0);
|
||||
|
||||
@@ -71,14 +71,14 @@ static void* GenerateToken(void* arg) {
|
||||
accumulative_token += delta;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class PerformanceTest {
|
||||
public:
|
||||
PerformanceTest(int attachment_size, bool echo_attachment)
|
||||
: _addr(NULL)
|
||||
, _channel(NULL)
|
||||
: _addr(nullptr)
|
||||
, _channel(nullptr)
|
||||
, _start_time(0)
|
||||
, _iterations(0)
|
||||
, _stop(false)
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
test::PerfTestRequest request;
|
||||
request.set_echo_attachment(_echo_attachment);
|
||||
test::PerfTestService_Stub stub(_channel);
|
||||
stub.Test(&cntl, &request, &response, NULL);
|
||||
stub.Test(&cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "RPC call failed: " << cntl.ErrorText();
|
||||
return -1;
|
||||
@@ -167,8 +167,8 @@ public:
|
||||
g_total_bytes.fetch_add(closure->cntl->request_attachment().size(), butil::memory_order_relaxed);
|
||||
g_total_cnt.fetch_add(1, butil::memory_order_relaxed);
|
||||
|
||||
cntl_guard.reset(NULL);
|
||||
response_guard.reset(NULL);
|
||||
cntl_guard.reset(nullptr);
|
||||
response_guard.reset(nullptr);
|
||||
|
||||
if (closure->test->_iterations == 0 && FLAGS_test_iterations > 0) {
|
||||
closure->test->_stop = true;
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
test->SendRequest();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -215,7 +215,7 @@ private:
|
||||
static void* DeleteTest(void* arg) {
|
||||
PerformanceTest* test = (PerformanceTest*)arg;
|
||||
delete test;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Test(int thread_num, int attachment_size) {
|
||||
@@ -239,7 +239,7 @@ void Test(int thread_num, int attachment_size) {
|
||||
bthread_t tid[thread_num];
|
||||
if (FLAGS_expected_qps > 0) {
|
||||
bthread_t tid;
|
||||
bthread_start_background(&tid, &BTHREAD_ATTR_NORMAL, GenerateToken, NULL);
|
||||
bthread_start_background(&tid, &BTHREAD_ATTR_NORMAL, GenerateToken, nullptr);
|
||||
}
|
||||
for (int k = 0; k < thread_num; ++k) {
|
||||
bthread_start_background(&tid[k], &BTHREAD_ATTR_NORMAL,
|
||||
|
||||
@@ -44,7 +44,7 @@ static bool access_redis(brpc::Channel& channel, const char* command) {
|
||||
}
|
||||
brpc::RedisResponse response;
|
||||
brpc::Controller cntl;
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to access redis, " << cntl.ErrorText();
|
||||
return false;
|
||||
@@ -83,7 +83,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_REDIS;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -113,7 +113,7 @@ int main(int argc, char* argv[]) {
|
||||
char prompt[64];
|
||||
snprintf(prompt, sizeof(prompt), "redis %s> ", FLAGS_server.c_str());
|
||||
std::unique_ptr<char, Freer> command(readline(prompt));
|
||||
if (command == NULL || *command == '\0') {
|
||||
if (command == nullptr || *command == '\0') {
|
||||
if (g_canceled) {
|
||||
// No input after the prompt and user pressed Ctrl-C,
|
||||
// quit the CLI.
|
||||
|
||||
@@ -87,7 +87,7 @@ int main(int argc, char* argv[]) {
|
||||
CHECK(request.AddCommand("set %s v1", key1.c_str()));
|
||||
CHECK(request.AddCommand("set %s v2", key2.c_str()));
|
||||
CHECK(request.AddCommand("mget %s %s", key1.c_str(), key2.c_str()));
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Sync call failed: " << cntl.ErrorText();
|
||||
return -1;
|
||||
@@ -104,7 +104,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
bthread::CountdownEvent event(1);
|
||||
Done done(&event);
|
||||
channel.CallMethod(NULL, &async_cntl, &async_request, &async_response, &done);
|
||||
channel.CallMethod(nullptr, &async_cntl, &async_request, &async_response, &done);
|
||||
event.wait();
|
||||
if (async_cntl.Failed()) {
|
||||
LOG(ERROR) << "Async call failed: " << async_cntl.ErrorText();
|
||||
|
||||
@@ -70,9 +70,9 @@ static void* sender(void* void_args) {
|
||||
brpc::RedisResponse response;
|
||||
brpc::Controller cntl;
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
args->redis_channel->CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
args->redis_channel->CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
const int64_t elp = cntl.latency_us();
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << elp;
|
||||
@@ -92,7 +92,7 @@ static void* sender(void* void_args) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -103,7 +103,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_REDIS;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -128,7 +128,7 @@ int main(int argc, char* argv[]) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
|
||||
channel.CallMethod(nullptr, &cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to access redis, " << cntl.ErrorText();
|
||||
return -1;
|
||||
@@ -156,13 +156,13 @@ int main(int argc, char* argv[]) {
|
||||
args[i].base_index = i * FLAGS_batch;
|
||||
args[i].redis_channel = &channel;
|
||||
if (!FLAGS_use_bthread) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &args[i]) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &args[i]) != 0) {
|
||||
&bids[i], nullptr, sender, &args[i]) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -179,9 +179,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "redis_client is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -44,7 +44,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -75,9 +75,9 @@ int main(int argc, char* argv[]) {
|
||||
// being serialized into protobuf messages.
|
||||
cntl.request_attachment().append(FLAGS_attachment);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
LOG(INFO) << "Received response from " << cntl.remote_side()
|
||||
<< " to " << cntl.local_side()
|
||||
|
||||
@@ -43,7 +43,7 @@ DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
|
||||
namespace example {
|
||||
|
||||
static const bthread_attr_t BTHREAD_ATTR_NORMAL_WITH_SPAN = {
|
||||
BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, NULL, BTHREAD_TAG_INVALID};
|
||||
BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, nullptr, BTHREAD_TAG_INVALID};
|
||||
|
||||
void* RunThreadFunc(void*) {
|
||||
TRACEPRINTF("RunThreadFunc %lu", bthread_self());
|
||||
@@ -51,7 +51,7 @@ void* RunThreadFunc(void*) {
|
||||
// A Channel represents a communication line to a Server. Notice that
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -69,9 +69,9 @@ void* RunThreadFunc(void*) {
|
||||
brpc::Controller cntl;
|
||||
request.set_message("hello world");
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
LOG(INFO) << "Received response from " << cntl.remote_side() << " to " << cntl.local_side()
|
||||
<< ": " << response.message() << " (attached=" << cntl.response_attachment()
|
||||
|
||||
@@ -65,9 +65,9 @@ static void* sender(void* arg) {
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
const int64_t elp = cntl.latency_us();
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
@@ -81,7 +81,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -144,7 +144,7 @@ int main(int argc, char* argv[]) {
|
||||
LOG(ERROR) << "Fail to init sub channel[" << i << "] of pchan";
|
||||
return -1;
|
||||
}
|
||||
if (sub_channel2->AddChannel(c, brpc::OWNS_CHANNEL, NULL, NULL) != 0) {
|
||||
if (sub_channel2->AddChannel(c, brpc::OWNS_CHANNEL, nullptr, nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to add sub channel[" << i << "] into pchan";
|
||||
return -1;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// Add another selective channel with default options.
|
||||
brpc::SelectiveChannel* sub_channel3 = new brpc::SelectiveChannel;
|
||||
if (sub_channel3->Init(FLAGS_load_balancer.c_str(), NULL) != 0) {
|
||||
if (sub_channel3->Init(FLAGS_load_balancer.c_str(), nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to init schan";
|
||||
return -1;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ int main(int argc, char* argv[]) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (sub_channel3->AddChannel(c, NULL)) {
|
||||
if (sub_channel3->AddChannel(c, nullptr)) {
|
||||
LOG(ERROR) << "Fail to add sub channel[" << i << "] into schan";
|
||||
return -1;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ int main(int argc, char* argv[]) {
|
||||
// Add all sub channels into schan.
|
||||
for (size_t i = 0; i < sub_channels.size(); ++i) {
|
||||
// note: we don't need the handle for channel removal;
|
||||
if (channel.AddChannel(sub_channels[i], NULL/*note*/) != 0) {
|
||||
if (channel.AddChannel(sub_channels[i], nullptr/*note*/) != 0) {
|
||||
LOG(ERROR) << "Fail to add sub_channel[" << i << "]";
|
||||
return -1;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -230,9 +230,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ int main(int argc, char* argv[]) {
|
||||
butil::StringSplitter sp(FLAGS_sleep_us.c_str(), ',');
|
||||
std::vector<int64_t> sleep_list;
|
||||
for (; sp; ++sp) {
|
||||
sleep_list.push_back(strtoll(sp.field(), NULL, 10));
|
||||
sleep_list.push_back(strtoll(sp.field(), nullptr, 10));
|
||||
}
|
||||
if (sleep_list.empty()) {
|
||||
sleep_list.push_back(0);
|
||||
|
||||
@@ -62,10 +62,10 @@ static void* sender(void* arg) {
|
||||
cntl.request_attachment().append(g_attachment);
|
||||
}
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
const int64_t start_time = butil::cpuwide_time_us();
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
const int64_t end_time = butil::cpuwide_time_us();
|
||||
const int64_t elp = end_time - start_time;
|
||||
if (!cntl.Failed()) {
|
||||
@@ -80,7 +80,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -91,7 +91,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = FLAGS_protocol;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -116,7 +116,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -141,9 +141,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ struct AsyncJob {
|
||||
static void* process_thread(void* args) {
|
||||
AsyncJob* job = static_cast<AsyncJob*>(args);
|
||||
job->run_and_delete();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Your implementation of example::EchoService
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
// and reused between different RPC. All session-local data are
|
||||
// destroyed upon server destruction.
|
||||
MySessionLocalData* sd = static_cast<MySessionLocalData*>(cntl->session_local_data());
|
||||
if (sd == NULL) {
|
||||
if (sd == nullptr) {
|
||||
cntl->SetFailed("Require ServerOptions.session_local_data_factory to be"
|
||||
" set with a correctly implemented instance");
|
||||
LOG(ERROR) << cntl->ErrorText();
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
// "tls" is short for "thread local storage".
|
||||
MyThreadLocalData* tls =
|
||||
static_cast<MyThreadLocalData*>(brpc::thread_local_data());
|
||||
if (tls == NULL) {
|
||||
if (tls == nullptr) {
|
||||
cntl->SetFailed("Require ServerOptions.thread_local_data_factory "
|
||||
"to be set with a correctly implemented instance");
|
||||
LOG(ERROR) << cntl->ErrorText();
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
// pthread_setspecific -> bthread_setspecific
|
||||
MyThreadLocalData* tls2 =
|
||||
static_cast<MyThreadLocalData*>(bthread_getspecific(_tls2_key));
|
||||
if (tls2 == NULL) {
|
||||
if (tls2 == nullptr) {
|
||||
tls2 = new MyThreadLocalData;
|
||||
CHECK_EQ(0, bthread_setspecific(_tls2_key, tls2));
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
job->response = response;
|
||||
job->done = done;
|
||||
bthread_t th;
|
||||
CHECK_EQ(0, bthread_start_background(&th, NULL, process_thread, job));
|
||||
CHECK_EQ(0, bthread_start_background(&th, nullptr, process_thread, job));
|
||||
|
||||
// We don't want to call done->Run() here, release the guard.
|
||||
done_guard.release();
|
||||
|
||||
@@ -61,13 +61,13 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_BAIDU_STD;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
options.max_retry = FLAGS_max_retry;
|
||||
if (channel.Init(FLAGS_server.c_str(), NULL) != 0) {
|
||||
if (channel.Init(FLAGS_server.c_str(), nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize channel";
|
||||
return -1;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ int main(int argc, char* argv[]) {
|
||||
example::EchoRequest request;
|
||||
example::EchoResponse response;
|
||||
request.set_message("I'm a RPC to connect stream");
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to connect stream, " << cntl.ErrorText();
|
||||
return -1;
|
||||
|
||||
@@ -37,13 +37,13 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_BAIDU_STD;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
options.max_retry = FLAGS_max_retry;
|
||||
if (channel.Init(FLAGS_server.c_str(), NULL) != 0) {
|
||||
if (channel.Init(FLAGS_server.c_str(), nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to initialize channel";
|
||||
return -1;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ int main(int argc, char* argv[]) {
|
||||
example::EchoService_Stub stub(&channel);
|
||||
brpc::Controller cntl;
|
||||
brpc::StreamId stream;
|
||||
if (brpc::StreamCreate(&stream, cntl, NULL) != 0) {
|
||||
if (brpc::StreamCreate(&stream, cntl, nullptr) != 0) {
|
||||
LOG(ERROR) << "Fail to create stream";
|
||||
return -1;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ int main(int argc, char* argv[]) {
|
||||
example::EchoRequest request;
|
||||
example::EchoResponse response;
|
||||
request.set_message("I'm a RPC to connect stream");
|
||||
stub.Echo(&cntl, &request, &response, NULL);
|
||||
stub.Echo(&cntl, &request, &response, nullptr);
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to connect stream, " << cntl.ErrorText();
|
||||
return -1;
|
||||
|
||||
@@ -42,7 +42,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_THRIFT;
|
||||
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
|
||||
@@ -63,7 +63,7 @@ int main(int argc, char* argv[]) {
|
||||
req.__set_data("hello");
|
||||
req.__set_need_by_proxy(10);
|
||||
|
||||
stub.CallMethod("Echo", &cntl, &req, &res, NULL);
|
||||
stub.CallMethod("Echo", &cntl, &req, &res, nullptr);
|
||||
|
||||
if (cntl.Failed()) {
|
||||
LOG(ERROR) << "Fail to send thrift request, " << cntl.ErrorText();
|
||||
|
||||
@@ -58,9 +58,9 @@ static void* sender(void* arg) {
|
||||
req.__set_data(g_request);
|
||||
req.__set_need_by_proxy(10);
|
||||
|
||||
// Because `done'(last parameter) is NULL, this function waits until
|
||||
// Because `done'(last parameter) is nullptr, this function waits until
|
||||
// the response comes back or error occurs(including timedout).
|
||||
stub.CallMethod("Echo", &cntl, &req, &res, NULL);
|
||||
stub.CallMethod("Echo", &cntl, &req, &res, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
g_latency_recorder << cntl.latency_us();
|
||||
} else {
|
||||
@@ -74,7 +74,7 @@ static void* sender(void* arg) {
|
||||
bthread_usleep(50000);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -85,7 +85,7 @@ int main(int argc, char* argv[]) {
|
||||
// Channel is thread-safe and can be shared by all threads in your program.
|
||||
brpc::Channel channel;
|
||||
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_THRIFT;
|
||||
options.connection_type = FLAGS_connection_type;
|
||||
@@ -112,7 +112,7 @@ int main(int argc, char* argv[]) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
|
||||
if (pthread_create(&pids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create pthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ int main(int argc, char* argv[]) {
|
||||
bids.resize(FLAGS_thread_num);
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (bthread_start_background(
|
||||
&bids[i], NULL, sender, &channel) != 0) {
|
||||
&bids[i], nullptr, sender, &channel) != 0) {
|
||||
LOG(ERROR) << "Fail to create bthread";
|
||||
return -1;
|
||||
}
|
||||
@@ -137,9 +137,9 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << "EchoClient is going to quit";
|
||||
for (int i = 0; i < FLAGS_thread_num; ++i) {
|
||||
if (!FLAGS_use_bthread) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[i], nullptr);
|
||||
} else {
|
||||
bthread_join(bids[i], NULL);
|
||||
bthread_join(bids[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ DEFINE_int32(max_concurrency, 0, "Limit of request processing in parallel");
|
||||
class EchoServiceImpl : public brpc::ThriftService {
|
||||
public:
|
||||
EchoServiceImpl() {
|
||||
// Initialize the channel, NULL means using default options.
|
||||
// Initialize the channel, nullptr means using default options.
|
||||
brpc::ChannelOptions options;
|
||||
options.protocol = brpc::PROTOCOL_THRIFT;
|
||||
if (_channel.Init("0.0.0.0", FLAGS_port , &options) != 0) {
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
// TODO: Following Cast<> drops data field from ProxyRequest which
|
||||
// does not recognize the field, should be debugged further.
|
||||
// LOG(INFO) << "req=" << *req->Cast<example::ProxyRequest>();
|
||||
stub.CallMethod("RealEcho", &cntl, req, res, NULL);
|
||||
stub.CallMethod("RealEcho", &cntl, req, res, nullptr);
|
||||
done->Run();
|
||||
} else if (cntl->thrift_method_name() == "RealEcho") {
|
||||
return RealEcho(cntl, req->Cast<example::EchoRequest>(),
|
||||
|
||||
@@ -71,14 +71,14 @@ static void* GenerateToken(void* arg) {
|
||||
accumulative_token += delta;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class PerformanceTest {
|
||||
public:
|
||||
PerformanceTest(int attachment_size, bool echo_attachment)
|
||||
: _addr(NULL)
|
||||
, _channel(NULL)
|
||||
: _addr(nullptr)
|
||||
, _channel(nullptr)
|
||||
, _start_time(0)
|
||||
, _iterations(0)
|
||||
, _stop(false)
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
test::PerfTestRequest request;
|
||||
request.set_echo_attachment(_echo_attachment);
|
||||
test::PerfTestService_Stub stub(_channel);
|
||||
stub.Test(&cntl, &request, &response, NULL);
|
||||
stub.Test(&cntl, &request, &response, nullptr);
|
||||
if (!cntl.Failed()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -179,8 +179,8 @@ public:
|
||||
g_total_bytes.fetch_add(closure->cntl->request_attachment().size(), butil::memory_order_relaxed);
|
||||
g_total_cnt.fetch_add(1, butil::memory_order_relaxed);
|
||||
|
||||
cntl_guard.reset(NULL);
|
||||
response_guard.reset(NULL);
|
||||
cntl_guard.reset(nullptr);
|
||||
response_guard.reset(nullptr);
|
||||
|
||||
if (closure->test->_iterations == 0 && FLAGS_test_iterations > 0) {
|
||||
closure->test->_stop = true;
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
test->SendRequest();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -227,7 +227,7 @@ private:
|
||||
static void* DeleteTest(void* arg) {
|
||||
PerformanceTest* test = (PerformanceTest*)arg;
|
||||
delete test;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Test(int thread_num, int attachment_size) {
|
||||
@@ -251,7 +251,7 @@ void Test(int thread_num, int attachment_size) {
|
||||
bthread_t tid[thread_num];
|
||||
if (FLAGS_expected_qps > 0) {
|
||||
bthread_t tid;
|
||||
bthread_start_background(&tid, &BTHREAD_ATTR_NORMAL, GenerateToken, NULL);
|
||||
bthread_start_background(&tid, &BTHREAD_ATTR_NORMAL, GenerateToken, nullptr);
|
||||
}
|
||||
for (int k = 0; k < thread_num; ++k) {
|
||||
bthread_start_background(&tid[k], &BTHREAD_ATTR_NORMAL,
|
||||
@@ -282,7 +282,7 @@ void Test(int thread_num, int attachment_size) {
|
||||
bthread_start_background(&tid[k], &BTHREAD_ATTR_NORMAL, DeleteTest, tests[k]);
|
||||
}
|
||||
for (int k = 0; k < thread_num; ++k) {
|
||||
bthread_join(tid[k], NULL);
|
||||
bthread_join(tid[k], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user