From 704889c12d9b2a432fa4ea67411801414968af00 Mon Sep 17 00:00:00 2001 From: chenBright Date: Wed, 19 Aug 2026 22:52:26 +0800 Subject: [PATCH] Refactor NULL with nullptr in docs --- docs/cn/backup_request.md | 2 +- docs/cn/bthread_or_not.md | 4 ++-- docs/cn/bvar_c++.md | 4 ++-- docs/cn/client.md | 12 ++++++------ docs/cn/combo_channel.md | 24 +++++++++++------------ docs/cn/coroutine.md | 6 +++--- docs/cn/endpoint.md | 2 +- docs/cn/error_code.md | 2 +- docs/cn/execution_queue.md | 10 +++++----- docs/cn/flatmap.md | 2 +- docs/cn/http_client.md | 14 ++++++------- docs/cn/http_service.md | 6 +++--- docs/cn/mbvar_c++.md | 12 ++++++------ docs/cn/memcache_client.md | 6 +++--- docs/cn/mysql_client.md | 20 +++++++++---------- docs/cn/nshead_service.md | 4 ++-- docs/cn/redis_client.md | 8 ++++---- docs/cn/rpc_replay.md | 2 +- docs/cn/rpcz.md | 2 +- docs/cn/server.md | 38 ++++++++++++++++++------------------ docs/cn/streaming_rpc.md | 10 +++++----- docs/cn/thrift.md | 2 +- docs/cn/ub_client.md | 14 ++++++------- docs/en/backup_request.md | 2 +- docs/en/bvar_c++.md | 4 ++-- docs/en/client.md | 12 ++++++------ docs/en/combo_channel.md | 28 +++++++++++++------------- docs/en/couchbase_example.md | 24 +++++++++++------------ docs/en/error_code.md | 2 +- docs/en/http_client.md | 14 ++++++------- docs/en/http_service.md | 6 +++--- docs/en/memcache_client.md | 6 +++--- docs/en/new_protocol.md | 6 +++--- docs/en/redis_client.md | 6 +++--- docs/en/server.md | 38 ++++++++++++++++++------------------ docs/en/streaming_rpc.md | 10 +++++----- docs/en/thrift.md | 2 +- 37 files changed, 183 insertions(+), 183 deletions(-) diff --git a/docs/cn/backup_request.md b/docs/cn/backup_request.md index b2e0bb61e0..bf9aa55be5 100644 --- a/docs/cn/backup_request.md +++ b/docs/cn/backup_request.md @@ -79,7 +79,7 @@ channel.Init(..., &options); | `window_size_seconds` | 10 | 滑动窗口宽度(秒),取值范围 [1, 3600] | | `update_interval_seconds` | 5 | 缓存刷新间隔(秒),必须 >= 1 | -参数不合法时 `CreateRateLimitedBackupPolicy` 返回 `NULL`。 +参数不合法时 `CreateRateLimitedBackupPolicy` 返回 `nullptr`。 ### 使用自定义 BackupRequestPolicy diff --git a/docs/cn/bthread_or_not.md b/docs/cn/bthread_or_not.md index 27432caf8f..2b71c90dd7 100644 --- a/docs/cn/bthread_or_not.md +++ b/docs/cn/bthread_or_not.md @@ -36,11 +36,11 @@ brpc中的异步和单线程的异步是完全不同的,异步回调会运行 bool search() { ... bthread th1, th2; - if (bthread_start_background(&th1, NULL, part1, part1_args) != 0) { + if (bthread_start_background(&th1, nullptr, part1, part1_args) != 0) { LOG(ERROR) << "Fail to create bthread for part1"; return false; } - if (bthread_start_background(&th2, NULL, part2, part2_args) != 0) { + if (bthread_start_background(&th2, nullptr, part2, part2_args) != 0) { LOG(ERROR) << "Fail to create bthread for part2"; return false; } diff --git a/docs/cn/bvar_c++.md b/docs/cn/bvar_c++.md index ddc0de1b0a..a829996b8e 100644 --- a/docs/cn/bvar_c++.md +++ b/docs/cn/bvar_c++.md @@ -326,7 +326,7 @@ class Variable { ... // Find all exposed variables matching `white_wildcards' but // `black_wildcards' and send them to `dumper'. - // Use default options when `options' is NULL. + // Use default options when `options' is nullptr. // Return number of dumped variables, -1 on error. static int dump_exposed(Dumper* dumper, const DumpOptions* options); }; @@ -634,7 +634,7 @@ static void get_username(std::ostream& os, void*) { os << "unknown"; } } -PassiveStatus g_username("process_username", get_username, NULL); +PassiveStatus g_username("process_username", get_username, nullptr); ``` # bvar::GFlag diff --git a/docs/cn/client.md b/docs/cn/client.md index bb16eefb68..a353114734 100755 --- a/docs/cn/client.md +++ b/docs/cn/client.md @@ -23,7 +23,7 @@ Channel可以**被所有线程共用**,你不需要为每个线程创建独立 2. 共用资源。比如server和channel可以共用后台线程。(bthread的工作线程) 3. 生命周期。析构ClientManager的过程很容易出错,现在由框架负责则不会有问题。 -就像大部分类那样,Channel必须在**Init**之后才能使用,options为NULL时所有参数取默认值,如果你要使用非默认值,这么做就行了: +就像大部分类那样,Channel必须在**Init**之后才能使用,options为nullptr时所有参数取默认值,如果你要使用非默认值,这么做就行了: ```c++ brpc::ChannelOptions options; // 包含了默认值 options.xxx = yyy; @@ -37,7 +37,7 @@ Init函数分为连接一台服务器和连接服务集群。 # 连接一台服务器 ```c++ -// options为NULL时取默认值 +// options为nullptr时取默认值 int Init(EndPoint server_addr_and_port, const ChannelOptions* options); int Init(const char* server_addr_and_port, const ChannelOptions* options); int Init(const char* server_addr, int port, const ChannelOptions* options); @@ -68,7 +68,7 @@ int Init(const char* naming_service_url, 你**不应该**在每次请求前动态地创建此类(连接服务集群的)Channel。因为创建和析构此类Channel牵涉到较多的资源,比如在创建时得访问一次命名服务,否则便不知道有哪些服务器可选。由于Channel可被多个线程共用,一般也没有必要动态创建。 -当`load_balancer_name`为NULL或空时,此Init等同于连接单台server的Init,`naming_service_url`应该是"ip:port"或"域名:port"。你可以通过这个Init函数统一Channel的初始化方式。比如你可以把`naming_service_url`和`load_balancer_name`放在配置文件中,要连接单台server时把`load_balancer_name`置空,要连接服务集群时则设置一个有效的算法名称。 +当`load_balancer_name`为nullptr或空时,此Init等同于连接单台server的Init,`naming_service_url`应该是"ip:port"或"域名:port"。你可以通过这个Init函数统一Channel的初始化方式。比如你可以把`naming_service_url`和`load_balancer_name`放在配置文件中,要连接单台server时把`load_balancer_name`置空,要连接服务集群时则设置一个有效的算法名称。 ## 命名服务 @@ -208,7 +208,7 @@ struct ServerNode { ``` 常见的业务策略如根据server的tag进行过滤。 -自定义的过滤器配置在ChannelOptions中,默认为NULL(不过滤)。 +自定义的过滤器配置在ChannelOptions中,默认为nullptr(不过滤)。 ```c++ class MyNamingServiceFilter : public brpc::NamingServiceFilter { @@ -308,7 +308,7 @@ stub.some_method(controller, request, response, done); ```c++ XXX_Stub(&channel).some_method(controller, request, response, done); ``` -一个例外是http/h2 client。访问http服务和protobuf没什么关系,直接调用CallMethod即可,除了Controller和done均为NULL,详见[访问http/h2服务](http_client.md)。 +一个例外是http/h2 client。访问http服务和protobuf没什么关系,直接调用CallMethod即可,除了Controller和done均为nullptr,详见[访问http/h2服务](http_client.md)。 ## 同步访问 @@ -323,7 +323,7 @@ XXX_Stub stub(&channel); request.set_foo(...); cntl.set_timeout_ms(...); -stub.some_method(&cntl, &request, &response, NULL); +stub.some_method(&cntl, &request, &response, nullptr); if (cntl->Failed()) { // RPC失败了. response里的值是未定义的,勿用。 } else { diff --git a/docs/cn/combo_channel.md b/docs/cn/combo_channel.md index fba4f6be69..3c6fac1c59 100644 --- a/docs/cn/combo_channel.md +++ b/docs/cn/combo_channel.md @@ -48,7 +48,7 @@ int AddChannel(brpc::ChannelBase* sub_channel, ## CallMapper -用于把对ParallelChannel的调用转化为对sub channel的调用。如果call_mapper是NULL,sub channel的请求就是ParallelChannel的请求,而response则New()自ParallelChannel的response。如果call_mapper不为NULL,则会在ParallelChannel析构时被删除。call_mapper内含引用计数,一个call_mapper可与多个sub channel关联。 +用于把对ParallelChannel的调用转化为对sub channel的调用。如果call_mapper是nullptr,sub channel的请求就是ParallelChannel的请求,而response则New()自ParallelChannel的response。如果call_mapper不为nullptr,则会在ParallelChannel析构时被删除。call_mapper内含引用计数,一个call_mapper可与多个sub channel关联。 ```c++ class CallMapper { @@ -80,7 +80,7 @@ method/request/response:ParallelChannel.CallMethod()的参数。 常见的Map()实现有: -- 广播request。这也是call_mapper为NULL时的行为: +- 广播request。这也是call_mapper为nullptr时的行为: ```c++ class Broadcaster : public CallMapper { public: @@ -142,7 +142,7 @@ sub_cntl:sub channel的请求对应的controller。默认实现:拷贝main_c ## ResponseMerger -response_merger把sub channel的response合并入总的response,其为NULL时,则使用response->MergeFrom(*sub_response),MergeFrom的行为可概括为“除了合并repeated字段,其余都是覆盖”。如果你需要更复杂的行为,则需实现ResponseMerger。response_merger是一个个执行的,所以你并不需要考虑多个Merge同时运行的情况。response_merger在ParallelChannel析构时被删除。response_merger内含引用计数,一个response_merger可与多个sub channel关联。 +response_merger把sub channel的response合并入总的response,其为nullptr时,则使用response->MergeFrom(*sub_response),MergeFrom的行为可概括为“除了合并repeated字段,其余都是覆盖”。如果你需要更复杂的行为,则需实现ResponseMerger。response_merger是一个个执行的,所以你并不需要考虑多个Merge同时运行的情况。response_merger在ParallelChannel析构时被删除。response_merger内含引用计数,一个response_merger可与多个sub channel关联。 Result的取值有: - MERGED: 成功合并。 @@ -157,13 +157,13 @@ Result的取值有: ```c++ // Get the controllers for accessing sub channels in combo channels. // Ordinary channel: -// sub_count() is 0 and sub() is always NULL. +// sub_count() is 0 and sub() is always nullptr. // ParallelChannel/PartitionChannel: // sub_count() is #sub-channels and sub(i) is the controller for // accessing i-th sub channel inside ParallelChannel, if i is outside -// [0, sub_count() - 1], sub(i) is NULL. -// NOTE: You must test sub() against NULL, ALWAYS. Even if i is inside -// range, sub(i) can still be NULL: +// [0, sub_count() - 1], sub(i) is nullptr. +// NOTE: You must test sub() against nullptr, ALWAYS. Even if i is inside +// range, sub(i) can still be nullptr: // * the rpc call may fail and terminate before accessing the sub channel // * the sub channel was skipped // SelectiveChannel/DynamicPartitionChannel: @@ -211,7 +211,7 @@ if (schan.Init(load_balancer, &schan_options) != 0) { 初始化完毕后通过AddChannel加入sub channel。 ```c++ -if (schan.AddChannel(sub_channel, NULL/*ChannelHandle*/) != 0) { // 第二个参数ChannelHandle用于删除sub channel,不用删除可填NULL +if (schan.AddChannel(sub_channel, nullptr/*ChannelHandle*/) != 0) { // 第二个参数ChannelHandle用于删除sub channel,不用删除可填nullptr LOG(ERROR) << "Fail to add sub_channel"; return -1; } @@ -249,18 +249,18 @@ if (channel.Init("c_murmurhash", &schan_options) != 0) { for (int i = 0; i < 3; ++i) { brpc::Channel* sub_channel = new brpc::Channel; - if (sub_channel->Init(ns_node_name[i], "rr", NULL) != 0) { + if (sub_channel->Init(ns_node_name[i], "rr", nullptr) != 0) { LOG(ERROR) << "Fail to init sub channel " << i; return -1; } - if (channel.AddChannel(sub_channel, NULL/*handle for removal*/) != 0) { + if (channel.AddChannel(sub_channel, nullptr/*handle for removal*/) != 0) { LOG(ERROR) << "Fail to add sub_channel to channel"; return -1; } } ... XXXService_Stub stub(&channel); -stub.FooMethod(&cntl, &request, &response, NULL); +stub.FooMethod(&cntl, &request, &response, nullptr); ... ``` @@ -288,7 +288,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); diff --git a/docs/cn/coroutine.md b/docs/cn/coroutine.md index cdce5b9e0a..efaf4d1c9e 100644 --- a/docs/cn/coroutine.md +++ b/docs/cn/coroutine.md @@ -41,7 +41,7 @@ brpc::experimental::Awaitable RpcCall(brpc::Channel& channel) { brpc::experimental::Awaitable CoroutineMain(const char* server) { brpc::Channel channel; - channel.Init(server, NULL); + channel.Init(server, nullptr); // co_await会从Awaitable得到int类型的返回值 int code = co_await RpcCall(channel); printf("Rpc result:%d\n", code); @@ -120,7 +120,7 @@ brpc::experimental::Awaitable inplace_func() { ```cpp brpc::experimental::Awaitable CoroutineMain(const char* server) { brpc::Channel channel; - channel.Init(server, NULL); + channel.Init(server, nullptr); brpc::experimental::Awaitable awaitable = RpcCall(channel); int code = co_await awaitable; @@ -141,7 +141,7 @@ brpc::experimental::Awaitable CoroutineMain(const char* server) { // co_await之前的逻辑,保持不变 brpc::Channel channel; - channel.Init(server, NULL); + channel.Init(server, nullptr); brpc::experimental::Awaitable awaitable = RpcCall(channel); // co_await的逻辑,转成一个await_suspend的函数调用,传入一个callback函数 diff --git a/docs/cn/endpoint.md b/docs/cn/endpoint.md index 10a0ea3b35..5320b6ded1 100644 --- a/docs/cn/endpoint.md +++ b/docs/cn/endpoint.md @@ -18,7 +18,7 @@ sa_family_t type = get_endpoint_type(ep); // 可能为AF_INET、AF_INET6或AF_UN LOG(DEBUG) << ep; // 打印EndPoint std::string ep_str = endpoint2str(ep).c_str(); // EndPoint转str tcp_listen(ep); // 用监听EndPoint表示的tcp端口 -tcp_connect(ep, NULL); // 用连接EndPoint表示的tcp端口 +tcp_connect(ep, nullptr); // 用连接EndPoint表示的tcp端口 sockaddr_storage ss; socklen_t socklen = 0; diff --git a/docs/cn/error_code.md b/docs/cn/error_code.md index 7cd36b72c6..92f340f415 100644 --- a/docs/cn/error_code.md +++ b/docs/cn/error_code.md @@ -61,7 +61,7 @@ strerror和strerror_r不认识使用BAIDU_REGISTER_ERRNO定义的错误码,自 ```c++ errno = ESTOP; printf("Describe errno: %m\n"); // [Wrong] Describe errno: Unknown error -114 -printf("Describe errno: %s\n", strerror_r(errno, NULL, 0)); // [Wrong] Describe errno: Unknown error -114 +printf("Describe errno: %s\n", strerror_r(errno, nullptr, 0)); // [Wrong] Describe errno: Unknown error -114 printf("Describe errno: %s\n", berror()); // [Correct] Describe errno: the thread is stopping printf("Describe errno: %s\n", berror(errno)); // [Correct] Describe errno: the thread is stopping ``` diff --git a/docs/cn/execution_queue.md b/docs/cn/execution_queue.md index 8640a4afb2..32d4d2d43b 100644 --- a/docs/cn/execution_queue.md +++ b/docs/cn/execution_queue.md @@ -85,16 +85,16 @@ struct ExecutionQueueOptions { bool use_pthread; // Attribute of the bthread which execute runs on. default: BTHREAD_ATTR_NORMAL - // Bthread will be used when executor = NULL and use_pthread == false. + // Bthread will be used when executor = nullptr and use_pthread == false. bthread_attr_t bthread_attr; - // Executor that tasks run on. default: NULL + // Executor that tasks run on. default: nullptr // Note that TaskOptions.in_place_if_possible = false will not work, if implementation of // Executor is in-place(synchronous). Executor * executor; }; -// Start a ExecutionQueue. If |options| is NULL, the queue will be created with +// Start a ExecutionQueue. If |options| is nullptr, the queue will be created with // default options. // Returns 0 on success, errno otherwise // NOTE: type |T| can be non-POD but must be copy-constructible @@ -172,8 +172,8 @@ int execution_queue_execute(ExecutionQueueId id, // Thread-safe and Wait-free. // Execute a task with options. e.g // bthread::execution_queue_execute(queue, task, &bthread::TASK_OPTIONS_URGENT) -// If |options| is NULL, we will use default options (normal task) -// If |handle| is not NULL, we will assign it with the handler of this task. +// If |options| is nullptr, we will use default options (normal task) +// If |handle| is not nullptr, we will assign it with the handler of this task. template int execution_queue_execute(ExecutionQueueId id, typename butil::add_const_reference::type task, diff --git a/docs/cn/flatmap.md b/docs/cn/flatmap.md index 814558ac59..7a21559aa9 100644 --- a/docs/cn/flatmap.md +++ b/docs/cn/flatmap.md @@ -19,7 +19,7 @@ void flatmap_example() { map.insert(10, "hello"); map[20] = "world"; std::string* value = map.seek(20); - CHECK(value != NULL); + CHECK(value != nullptr); CHECK_EQ(2UL, map.size()); CHECK_EQ(0UL, map.erase(30)); diff --git a/docs/cn/http_client.md b/docs/cn/http_client.md index f5fea9f3a8..b9767aab97 100644 --- a/docs/cn/http_client.md +++ b/docs/cn/http_client.md @@ -32,10 +32,10 @@ http/h2 channel也支持bns地址或其他NamingService。 ```c++ brpc::Controller cntl; cntl.http_request().uri() = "www.baidu.com/index.html"; // 设置为待访问的URL -channel.CallMethod(NULL, &cntl, NULL, NULL, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr/*done*/); ``` -HTTP/h2和protobuf关系不大,所以除了Controller和done,CallMethod的其他参数均为NULL。如果要异步操作,最后一个参数传入done。 +HTTP/h2和protobuf关系不大,所以除了Controller和done,CallMethod的其他参数均为nullptr。如果要异步操作,最后一个参数传入done。 `cntl.response_attachment()`是回复的body,类型也是butil::IOBuf。IOBuf可通过to_string()转化为std::string,但是需要分配内存并拷贝所有内容,如果关注性能,处理过程应直接支持IOBuf,而不要求连续内存。 @@ -48,7 +48,7 @@ brpc::Controller cntl; cntl.http_request().uri() = "..."; // 设置为待访问的URL cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"hello world!\"}"); -channel.CallMethod(NULL, &cntl, NULL, NULL, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr/*done*/); ``` 需要大量打印过程的body建议使用butil::IOBufBuilder,它的用法和std::ostringstream是一样的。对于有大量对象要打印的场景,IOBufBuilder简化了代码,效率也可能比c-style printf更高。 @@ -60,7 +60,7 @@ cntl.http_request().set_method(brpc::HTTP_METHOD_POST); butil::IOBufBuilder os; os << "A lot of printing" << printable_objects << ...; os.move_to(cntl.request_attachment()); -channel.CallMethod(NULL, &cntl, NULL, NULL, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr/*done*/); ``` # 控制HTTP版本 @@ -126,7 +126,7 @@ URL的一般形式如下图: 访问名为Foo的header ```c++ -const std::string* value = cntl->http_request().GetHeader("Foo"); //不存在为NULL +const std::string* value = cntl->http_request().GetHeader("Foo"); //不存在为nullptr ``` 设置名为Foo的header ```c++ @@ -134,7 +134,7 @@ cntl->http_request().SetHeader("Foo", "value"); ``` 访问名为Foo的query ```c++ -const std::string* value = cntl->http_request().uri().GetQuery("Foo"); // 不存在为NULL +const std::string* value = cntl->http_request().uri().GetQuery("Foo"); // 不存在为nullptr ``` 设置名为Foo的query ```c++ @@ -197,7 +197,7 @@ Notes on http header: #include ... const std::string* encoding = cntl->http_response().GetHeader("Content-Encoding"); -if (encoding != NULL && *encoding == "gzip") { +if (encoding != nullptr && *encoding == "gzip") { butil::IOBuf uncompressed; if (!brpc::policy::GzipDecompress(cntl->response_attachment(), &uncompressed)) { LOG(ERROR) << "Fail to un-gzip response body"; diff --git a/docs/cn/http_service.md b/docs/cn/http_service.md index 88bb46fc4d..f3bb70c8f7 100644 --- a/docs/cn/http_service.md +++ b/docs/cn/http_service.md @@ -213,7 +213,7 @@ query string也是key/value对,http headers与query string的区别: ```c++ // 获得header中"User-Agent"的值,大小写不敏感。 const std::string* user_agent_str = cntl->http_request().GetHeader("User-Agent"); -if (user_agent_str != NULL) { // has the header +if (user_agent_str != nullptr) { // has the header LOG(TRACE) << "User-Agent is " << *user_agent_str; } ... @@ -272,7 +272,7 @@ cntl->http_response().SetHeader("Location", "http://bj.bs.bae.baidu.com/family/i ```c++ const std::string* time_value = cntl->http_request().uri().GetQuery("time"); -if (time_value != NULL) { // the query string is present +if (time_value != nullptr) { // the query string is present LOG(TRACE) << "time = " << *time_value; } @@ -306,7 +306,7 @@ http服务常对http body进行压缩,可以有效减少网页的传输时间 #include ... const std::string* encoding = cntl->http_request().GetHeader("Content-Encoding"); -if (encoding != NULL && *encoding == "gzip") { +if (encoding != nullptr && *encoding == "gzip") { butil::IOBuf uncompressed; if (!brpc::policy::GzipDecompress(cntl->request_attachment(), &uncompressed)) { LOG(ERROR) << "Fail to un-gzip request body"; diff --git a/docs/cn/mbvar_c++.md b/docs/cn/mbvar_c++.md index 1ce1364f24..f65fc62d44 100644 --- a/docs/cn/mbvar_c++.md +++ b/docs/cn/mbvar_c++.md @@ -184,7 +184,7 @@ class MVariable { ... ... // Find all exposed mvariables and send them to `dumper'. - // Use default options when `options' is NULL. + // Use default options when `options' is nullptr. // Return number of dumped mvariables, -1 on error. static size_t dump_exposed(Dumper* dumper, const DumpOptions* options); }; @@ -406,7 +406,7 @@ public: ... // Get real bvar pointer object - // Return real bvar pointer(Not NULL) on success, NULL otherwise. + // Return real bvar pointer(Not nullptr) on success, nullptr otherwise. T* get_stats(const std::list& labels_value); }; ``` @@ -462,10 +462,10 @@ int request_count = get_request_count(request_label_list); class MyStringView { public: - MyStringView() : _ptr(NULL), _len(0) {} + MyStringView() : _ptr(nullptr), _len(0) {} MyStringView(const char* str) : _ptr(str), - _len(str == NULL ? 0 : strlen(str)) {} + _len(str == nullptr ? 0 : strlen(str)) {} #if __cplusplus >= 201703L MyStringView(const std::string_view& str) : _ptr(str.data()), _len(str.size()) {} @@ -480,7 +480,7 @@ public: // Converts to `std::basic_string`. explicit operator std::string() const { - if (NULL == _ptr) { + if (nullptr == _ptr) { return {}; } return {_ptr, size()}; @@ -488,7 +488,7 @@ public: // Converts to butil::StringPiece. explicit operator butil::StringPiece() const { - if (NULL == _ptr) { + if (nullptr == _ptr) { return {}; } return {_ptr, size()}; diff --git a/docs/cn/memcache_client.md b/docs/cn/memcache_client.md index 2e7a8f6240..fb59b71b64 100644 --- a/docs/cn/memcache_client.md +++ b/docs/cn/memcache_client.md @@ -41,12 +41,12 @@ if (!request.Set("hello", "world", 0xdeadbeef/*flags*/, 10/*expiring seconds*/, LOG(FATAL) << "Fail to SET request"; return -1; } -channel.CallMethod(NULL, &cntl, &request, &response, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, &request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(FATAL) << "Fail to access memcached, " << cntl.ErrorText(); return -1; } -if (!response.PopSet(NULL)) { +if (!response.PopSet(nullptr)) { LOG(FATAL) << "Fail to SET memcached, " << response.LastError(); return -1; } @@ -55,7 +55,7 @@ if (!response.PopSet(NULL)) { 上述代码的说明: -- 请求类型必须为MemcacheRequest,回复类型必须为MemcacheResponse,否则CallMethod会失败。不需要stub,直接调用channel.CallMethod,method填NULL。 +- 请求类型必须为MemcacheRequest,回复类型必须为MemcacheResponse,否则CallMethod会失败。不需要stub,直接调用channel.CallMethod,method填nullptr。 - 调用request.XXX()增加操作,本例XXX=Set,一个request多次调用不同的操作,这些操作会被同时送到memcached(常被称为pipeline模式)。 - 依次调用response.PopXXX()弹出操作结果,本例XXX=Set,成功返回true,失败返回false,调用response.LastError()可获得错误信息。XXX必须和request的依次对应,否则失败。本例中若用PopGet就会失败,错误信息为“not a GET response"。 - Pop结果独立于RPC结果。即使“不能把某个值设入memcached”,RPC可能还是成功的。RPC失败指连接断开,超时之类的。如果业务上认为要成功操作才算成功,那么你不仅要判RPC成功,还要判PopXXX是成功的。 diff --git a/docs/cn/mysql_client.md b/docs/cn/mysql_client.md index 12e1d48d8e..02bbc6f6a8 100644 --- a/docs/cn/mysql_client.md +++ b/docs/cn/mysql_client.md @@ -44,7 +44,7 @@ if (!request.Query(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 { @@ -56,7 +56,7 @@ return true; 上述代码的说明: -- 请求类型必须为MysqlRequest,回复类型必须为MysqlResponse,否则CallMethod会失败。不需要stub,直接调用channel.CallMethod,method填NULL。 +- 请求类型必须为MysqlRequest,回复类型必须为MysqlResponse,否则CallMethod会失败。不需要stub,直接调用channel.CallMethod,method填nullptr。 - 调用request.Query()传入要执行的命令,可以批量执行命令,多个命令用分号隔开。 - 依次调用response.reply(X)弹出操作结果,根据返回类型的不同,选择不同的类型接收,如:MysqlReply::Ok,MysqlReply::Error,const MysqlReply::Columnconst MysqlReply::Row等。 - 如果只有一条命令则reply为1个,如果为批量操作返回的reply为多个。 @@ -94,7 +94,7 @@ const MysqlReply::Field& MysqlReply::Row::field(const uint64_t index) const; ```c++ rpc::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; @@ -113,7 +113,7 @@ brpc::MysqlTransactionOptions options; 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; } @@ -126,7 +126,7 @@ if (!request.Query(*it)) { } 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(); @@ -143,7 +143,7 @@ Prepared statement对于一个需要执行很多次的SQL语句,它把这个SQ ```c++ rpc::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; @@ -158,7 +158,7 @@ if (channel.Init(FLAGS_server.c_str(), FLAGS_port, &options) != 0) { } auto stmt(brpc::NewMysqlStatement(channel, "select * from tb where name=?")); -if (stmt == NULL) { +if (stmt == nullptr) { LOG(ERROR) << "Fail to create mysql statement"; return -1; } @@ -166,15 +166,15 @@ if (stmt == NULL) { brpc::MysqlRequest request(stmt.get()); if (!request.AddParam("lilei")) { LOG(ERROR) << "Fail to add name param"; - return NULL; + return nullptr; } 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; diff --git a/docs/cn/nshead_service.md b/docs/cn/nshead_service.md index 5bc0b4577d..0791b9c039 100644 --- a/docs/cn/nshead_service.md +++ b/docs/cn/nshead_service.md @@ -123,7 +123,7 @@ option.nshead_service = new brpc::policy::UbrpcCompackAdaptor; // mcpack2用Ubrp # 使用nshead+blob的服务 -[NsheadService](https://github.com/apache/brpc/blob/master/src/brpc/nshead_service.h)是brpc中所有处理nshead打头协议的基类,实现好的NsheadService实例得赋值给ServerOptions.nshead_service才能发挥作用。不赋值的话,默认是NULL,代表不支持任何nshead开头的协议,这个server被nshead开头的数据包访问时会报错。明显地,**一个Server只能处理一种以nshead开头的协议。** +[NsheadService](https://github.com/apache/brpc/blob/master/src/brpc/nshead_service.h)是brpc中所有处理nshead打头协议的基类,实现好的NsheadService实例得赋值给ServerOptions.nshead_service才能发挥作用。不赋值的话,默认是nullptr,代表不支持任何nshead开头的协议,这个server被nshead开头的数据包访问时会报错。明显地,**一个Server只能处理一种以nshead开头的协议。** NsheadService的接口如下,基本上用户只需要实现`ProcessNsheadRequest`这个函数。 @@ -218,7 +218,7 @@ public: // meta: was set by ParseNsheadMeta() // controller: If something goes wrong, call controller->SetFailed() // pb_res: the pb response that returned by pb method. [NOTE] `pb_res' - // can be NULL or uninitialized when RPC failed (indicated by + // can be nullptr or uninitialized when RPC failed (indicated by // Controller::Failed()), in which case you may put error // information into `nshead_res'. // nshead_res: the nshead response that will be sent back to client. diff --git a/docs/cn/redis_client.md b/docs/cn/redis_client.md index d0ac54458c..681e16f561 100644 --- a/docs/cn/redis_client.md +++ b/docs/cn/redis_client.md @@ -42,7 +42,7 @@ brpc::RedisRequest set_request; brpc::RedisResponse response; brpc::Controller cntl; set_request.AddCommand("SET %s %d", my_key.c_str(), my_number); -redis_channel.CallMethod(NULL, &cntl, &set_request, &response, NULL/*done*/); +redis_channel.CallMethod(nullptr, &cntl, &set_request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(ERROR) << "Fail to access redis-server"; return -1; @@ -63,7 +63,7 @@ brpc::RedisRequest incr_request; incr_request.AddCommand("INCR %s", my_key.c_str()); response.Clear(); cntl.Reset(); -redis_channel.CallMethod(NULL, &cntl, &incr_request, &response, NULL/*done*/); +redis_channel.CallMethod(nullptr, &cntl, &incr_request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(ERROR) << "Fail to access redis-server"; return -1; @@ -88,7 +88,7 @@ request.AddCommand("INCR counter1"); request.AddCommand("DECR counter1"); request.AddCommand("INCRBY counter1 10"); request.AddCommand("DECRBY counter1 20"); -redis_channel.CallMethod(NULL, &cntl, &request, &response, NULL/*done*/); +redis_channel.CallMethod(nullptr, &cntl, &request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(ERROR) << "Fail to access redis-server"; return -1; @@ -142,7 +142,7 @@ command_size()可获得(成功)加入的命令个数。 每个reply可能是: -- REDIS_REPLY_NIL:redis中的NULL,代表值不存在。可通过is_nil()判定。 +- REDIS_REPLY_NIL:redis中的nullptr,代表值不存在。可通过is_nil()判定。 - REDIS_REPLY_STATUS:在redis文档中称为Simple String。一般是操作的返回状态,比如SET返回的OK。可通过is_string()判定(和string相同),c_str()或data()获得值。 - REDIS_REPLY_STRING:在redis文档中称为Bulk String。大多数值都是这个类型,包括incr返回的。可通过is_string()判定,c_str()或data()获得值。 - REDIS_REPLY_ERROR:操作出错时的返回值,包含一段错误信息。可通过is_error()判定,error_message()获得错误信息。 diff --git a/docs/cn/rpc_replay.md b/docs/cn/rpc_replay.md index d1b23af8ea..2ff6c25b07 100644 --- a/docs/cn/rpc_replay.md +++ b/docs/cn/rpc_replay.md @@ -49,7 +49,7 @@ brpc提供了[SampleIterator](https://github.com/apache/brpc/blob/master/src/brp #include ... brpc::SampleIterator it("./rpc_data/rpc_dump/echo_server"); -for (brpc::SampledRequest* req = it->Next(); req != NULL; req = it->Next()) { +for (brpc::SampledRequest* req = it->Next(); req != nullptr; req = it->Next()) { ... // req->meta的类型是brpc::RpcDumpMeta,定义在src/brpc/rpc_dump.proto // req->request的类型是butil::IOBuf,对应格式说明中的"serialized request" diff --git a/docs/cn/rpcz.md b/docs/cn/rpcz.md index 12ba2ef3ea..f8ba62be95 100644 --- a/docs/cn/rpcz.md +++ b/docs/cn/rpcz.md @@ -62,7 +62,7 @@ TRACEPRINTF("Hello rpcz %d", 123); 有的业务在处理server请求的时候,会创建子bthread,在子bthread中发起rpc调用。默认情况下,子bthread中的rpc调用跟原来的请求无法建立关联,trace就会断掉。这种情况下,可以在创建子bthread时,指定BTHREAD_INHERIT_SPAN标志,来显式地建立trace上文关联,如: ```c++ -bthread_attr_t attr = { BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, NULL }; +bthread_attr_t attr = { BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, nullptr }; bthread_start_urgent(&tid, &attr, thread_proc, arg); ``` diff --git a/docs/cn/server.md b/docs/cn/server.md index bbce852228..7a9c47a4ef 100644 --- a/docs/cn/server.md +++ b/docs/cn/server.md @@ -120,13 +120,13 @@ public: // Constructed with a closure which will be Run() inside dtor. explicit ClosureGuard(google::protobuf::Closure* done); - // Call Run() of internal closure if it's not NULL. + // Call Run() of internal closure if it's not nullptr. ~ClosureGuard(); - // Call Run() of internal closure if it's not NULL and set it to `done'. + // Call Run() of internal closure if it's not nullptr and set it to `done'. void reset(google::protobuf::Closure* done); - // Set internal closure to NULL and return the one before set. + // Set internal closure to nullptr and return the one before set. google::protobuf::Closure* release(); }; ``` @@ -218,7 +218,7 @@ int Start(const char *ip_str, PortRange port_range, const ServerOptions *opt); 关于IPV6和Unix domain socket的使用,详见 [EndPoint](endpoint.md)。 -`options`为NULL时所有参数取默认值,如果你要使用非默认值,这么做就行了: +`options`为nullptr时所有参数取默认值,如果你要使用非默认值,这么做就行了: ```c++ brpc::ServerOptions options; // 包含了默认值 @@ -730,7 +730,7 @@ curl -s -m 1 :/flags/enable_dir_service,enable_threads_service | session-local data与一次server端RPC绑定: 从进入service回调开始,到调用server端的done结束,不管该service是同步还是异步处理。 session-local data会尽量被重用,在server停止前不会被删除。 -设置ServerOptions.session_local_data_factory后访问Controller.session_local_data()即可获得session-local数据。若没有设置,Controller.session_local_data()总是返回NULL。 +设置ServerOptions.session_local_data_factory后访问Controller.session_local_data()即可获得session-local数据。若没有设置,Controller.session_local_data()总是返回nullptr。 若ServerOptions.reserved_session_local_data大于0,Server会在提供服务前就创建这么多个数据。 @@ -755,7 +755,7 @@ public: // Get the session-local data which is created by ServerOptions.session_local_data_factory // and reused between different RPC. MySessionLocalData* sd = static_cast(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"); return; } @@ -766,9 +766,9 @@ public: struct ServerOptions { ... // The factory to create/destroy data attached to each RPC session. - // If this field is NULL, Controller::session_local_data() is always NULL. + // If this field is nullptr, Controller::session_local_data() is always nullptr. // NOT owned by Server and must be valid when Server is running. - // Default: NULL + // Default: nullptr const DataFactory* session_local_data_factory; // Prepare so many session-local data before server starts, so that calls @@ -812,7 +812,7 @@ int main(int argc, char* argv[]) { server-thread-local与一次service回调绑定,从进service回调开始,到出service回调结束。所有的server-thread-local data会被尽量重用,在server停止前不会被删除。在实现上server-thread-local是一个特殊的bthread-local。 -设置ServerOptions.thread_local_data_factory后访问brpc::thread_local_data()即可获得thread-local数据。若没有设置,brpc::thread_local_data()总是返回NULL。 +设置ServerOptions.thread_local_data_factory后访问brpc::thread_local_data()即可获得thread-local数据。若没有设置,brpc::thread_local_data()总是返回nullptr。 若ServerOptions.reserved_thread_local_data大于0,Server会在启动前就创建这么多个数据。 @@ -844,7 +844,7 @@ public: // and reused between different threads. // "tls" is short for "thread local storage". MyThreadLocalData* tls = static_cast(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"); return; @@ -857,9 +857,9 @@ struct ServerOptions { ... // The factory to create/destroy data attached to each searching thread // in server. - // If this field is NULL, brpc::thread_local_data() is always NULL. + // If this field is nullptr, brpc::thread_local_data() is always nullptr. // NOT owned by Server and must be valid when Server is running. - // Default: NULL + // Default: nullptr const DataFactory* thread_local_data_factory; // Prepare so many thread-local data before server starts, so that calls @@ -912,9 +912,9 @@ Session-local和server-thread-local对大部分server已经够用。不过在一 ```c++ // Create a key value identifying a slot in a thread-specific data area. // Each thread maintains a distinct thread-specific data area. -// `destructor', if non-NULL, is called with the value associated to that key +// `destructor', if non-nullptr, is called with the value associated to that key // when the key is destroyed. `destructor' is not called if the value -// associated is NULL when the key is destroyed. +// associated is nullptr when the key is destroyed. // Returns 0 on success, error code otherwise. extern int bthread_key_create(bthread_key_t* key, void (*destructor)(void* data)); @@ -942,8 +942,8 @@ extern int bthread_key_delete(bthread_key_t key); extern int bthread_setspecific(bthread_key_t key, void* data); // Return current value of the thread-specific slot identified by `key'. -// If bthread_setspecific() had not been called in the thread, return NULL. -// If the key is invalid or deleted, return NULL. +// If bthread_setspecific() had not been called in the thread, return nullptr. +// If the key is invalid or deleted, return nullptr. extern void* bthread_getspecific(bthread_key_t key); ``` @@ -951,7 +951,7 @@ extern void* bthread_getspecific(bthread_key_t key); 用bthread_key_create创建一个bthread_key_t,它代表一种bthread私有变量。 -用bthread_[get|set]specific查询和设置bthread私有变量。一个线程中第一次访问某个私有变量返回NULL。 +用bthread_[get|set]specific查询和设置bthread私有变量。一个线程中第一次访问某个私有变量返回nullptr。 在所有线程都不使用和某个bthread_key_t相关的私有变量后再删除它。如果删除了一个仍在被使用的bthread_key_t,相关的私有变量就泄露了。 @@ -970,7 +970,7 @@ if (bthread_key_create(&tls_key, my_data_destructor) != 0) { ```c++ // in some thread ... MyThreadLocalData* tls = static_cast(bthread_getspecific(tls_key)); -if (tls == NULL) { // First call to bthread_getspecific (and before any bthread_setspecific) returns NULL +if (tls == nullptr) { // First call to bthread_getspecific (and before any bthread_setspecific) returns nullptr tls = new MyThreadLocalData; // Create thread-local data on demand. CHECK_EQ(0, bthread_setspecific(tls_key, tls)); // set the data so that next time bthread_getspecific in the thread returns the data. } @@ -1010,7 +1010,7 @@ public: // pthread_getspecific -> bthread_getspecific // pthread_setspecific -> bthread_setspecific MyThreadLocalData* tls2 = static_cast(bthread_getspecific(_tls2_key)); - if (tls2 == NULL) { + if (tls2 == nullptr) { tls2 = new MyThreadLocalData; CHECK_EQ(0, bthread_setspecific(_tls2_key, tls2)); } diff --git a/docs/cn/streaming_rpc.md b/docs/cn/streaming_rpc.md index 6bdb2f2913..5191eb980f 100644 --- a/docs/cn/streaming_rpc.md +++ b/docs/cn/streaming_rpc.md @@ -45,23 +45,23 @@ struct StreamOptions // default: 128 size_t messages_in_batch; - // Handle input message, if handler is NULL, the remote side is not allowed to + // Handle input message, if handler is nullptr, the remote side is not allowed to // write any message, who will get EBADF on writing - // default: NULL + // default: nullptr StreamInputHandler* handler; }; // [Called at the client side] // Create a Stream at client-side along with the |cntl|, which will be connected // when receiving the response with a Stream from server-side. If |options| is -// NULL, the Stream will be created with default options +// nullptr, the Stream will be created with default options // Return 0 on success, -1 otherwise int StreamCreate(StreamId* request_stream, Controller &cntl, const StreamOptions* options); // [Called at the client side for creating multiple streams] // Create streams at client-side along with the |cntl|, which will be connected // when receiving the response with streams from server-side. If |options| is -// NULL, the stream will be created with default options +// nullptr, the stream will be created with default options // Return 0 on success, -1 otherwise int StreamCreate(StreamIds& request_streams, int request_stream_size, Controller& cntl, const StreamOptions* options); ``` @@ -129,7 +129,7 @@ int StreamWrite(StreamId stream_id, const butil::IOBuf &message); // Wait util the pending buffer size is less than |max_buf_size| or error occurs // Returns 0 on success, errno otherwise // Errno: -// - ETIMEDOUT: when |due_time| is not NULL and time expired this +// - ETIMEDOUT: when |due_time| is not nullptr and time expired this // - EINVAL: the Stream was close during waiting int StreamWait(StreamId stream_id, const timespec* due_time); diff --git a/docs/cn/thrift.md b/docs/cn/thrift.md index 9e1d4c99cb..eacbe259a1 100755 --- a/docs/cn/thrift.md +++ b/docs/cn/thrift.md @@ -70,7 +70,7 @@ example::EchoRequest req; example::EchoResponse res; req.data = "hello"; -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(); diff --git a/docs/cn/ub_client.md b/docs/cn/ub_client.md index f020b39195..bda80d68b7 100644 --- a/docs/cn/ub_client.md +++ b/docs/cn/ub_client.md @@ -90,7 +90,7 @@ r31687后,brpc支持通过protobuf访问ubrpc,不需要baidu-rpc-ub,也不 request.set_message("hello world"); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); if (cntl.Failed()) { LOG(ERROR) << "Fail to send request, " << cntl.ErrorText(); @@ -126,7 +126,7 @@ r31687后,brpc支持通过protobuf访问ubrpc,不需要baidu-rpc-ub,也不 multi_requests.mutable_req1()->set_message("hello"); multi_requests.mutable_req2()->set_message("world"); cntl.set_idl_names(brpc::idl_multi_req_multi_res); - stub.EchoWithMultiArgs(&cntl, &multi_requests, &multi_responses, NULL); + stub.EchoWithMultiArgs(&cntl, &multi_requests, &multi_responses, nullptr); if (cntl.Failed()) { LOG(ERROR) << "Fail to send request, " << cntl.ErrorText(); @@ -203,7 +203,7 @@ server端由public/ubrpc搭建,request/response使用idl文件描述字段, // 发起RPC brpc::Controller cntl; - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); if (cntl.Failed()) { LOG(ERROR) << "Fail to Echo, " << cntl.ErrorText(); @@ -247,7 +247,7 @@ request.set_message("hello world"); request.mutable_nshead()->version = 99; brpc::Controller cntl; -channel.CallMethod(NULL, &cntl, &request, &response, NULL); // 假设channel已经通过之前所述方法Init成功 +channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); // 假设channel已经通过之前所述方法Init成功 // Get `message' field of `EchoResponse' response.message(); @@ -293,7 +293,7 @@ if (ret != 0) { request.mutable_nshead()->version = 99; brpc::Controller cntl; -channel.CallMethod(NULL, &cntl, &request, &response, NULL); // 假设channel已经通过之前所述方法Init成功 +channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); // 假设channel已经通过之前所述方法Init成功 // Get response from response buffer const mc_pack_t* res_pack = response.McpackHandle(); @@ -328,7 +328,7 @@ request.head.version = 99; 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 the server: " << cntl.ErrorText(); @@ -364,7 +364,7 @@ request.append("hello world"); request.mutable_nshead()->version = 99; brpc::Controller cntl; -channel.CallMethod(NULL, &cntl, &request, &response, NULL); // 假设channel已经通过之前所述方法Init成功 +channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); // 假设channel已经通过之前所述方法Init成功 // Process response. response.data() is the buffer, response.size() is the length. ``` diff --git a/docs/en/backup_request.md b/docs/en/backup_request.md index e61f361182..848cd5ae58 100644 --- a/docs/en/backup_request.md +++ b/docs/en/backup_request.md @@ -79,7 +79,7 @@ channel.Init(..., &options); | `window_size_seconds` | 10 | Sliding window width in seconds; range [1, 3600] | | `update_interval_seconds` | 5 | Cached-ratio refresh interval in seconds; must be >= 1 | -`CreateRateLimitedBackupPolicy` returns `NULL` if any parameter is invalid. +`CreateRateLimitedBackupPolicy` returns `nullptr` if any parameter is invalid. ### Using a custom BackupRequestPolicy diff --git a/docs/en/bvar_c++.md b/docs/en/bvar_c++.md index 160cdfcc08..9f58859419 100644 --- a/docs/en/bvar_c++.md +++ b/docs/en/bvar_c++.md @@ -281,7 +281,7 @@ Common needs for exporting are querying by HTTP API and writing into local file, ... // Find all exposed variables matching `white_wildcards' but // `black_wildcards' and send them to `dumper'. - // Use default options when `options' is NULL. + // Use default options when `options' is nullptr. // Return number of dumped variables, -1 on error. static int dump_exposed(Dumper* dumper, const DumpOptions* options); }; @@ -472,7 +472,7 @@ static void get_username(std::ostream& os, void*) { os << "unknown"; } } -PassiveStatus g_username("process_username", get_username, NULL); +PassiveStatus g_username("process_username", get_username, nullptr); ``` diff --git a/docs/en/client.md b/docs/en/client.md index 8da0c6b156..087c39b53c 100644 --- a/docs/en/client.md +++ b/docs/en/client.md @@ -23,7 +23,7 @@ Some RPC implementations have so-called "ClientManager", including configuration 2. Share resources. For example, servers and channels in brpc share background workers (of bthread). 3. Better management of Lifetime. Destructing a "ClientManager" is very error-prone, which is managed by brpc right now. -Like most classes, Channel must be **Init()**-ed before usage. Parameters take default values when `options` is NULL. If you want non-default values, code as follows: +Like most classes, Channel must be **Init()**-ed before usage. Parameters take default values when `options` is nullptr. If you want non-default values, code as follows: ```c++ brpc::ChannelOptions options; // including default values options.xxx = yyy; @@ -37,7 +37,7 @@ Init() can connect one server or a cluster(multiple servers). # Connect to a server ```c++ -// Take default values when options is NULL. +// Take default values when options is nullptr. int Init(EndPoint server_addr_and_port, const ChannelOptions* options); int Init(const char* server_addr_and_port, const ChannelOptions* options); int Init(const char* server_addr, int port, const ChannelOptions* options); @@ -64,7 +64,7 @@ Channels created by above Init() get server list from the NamingService specifie You **should not** create such channels ad-hocly each time before a RPC, because creation and destroying of such channels relate to many resources, say NamingService needs to be accessed once at creation otherwise server candidates are unknown. On the other hand, channels are able to be shared by multiple threads safely and has no need to be created frequently. -If `load_balancer_name` is NULL or empty, this Init() is just the one for connecting single server and `naming_service_url` should be "ip:port" or "host:port" of the server. Thus you can unify initialization of all channels with this Init(). For example, you can put values of `naming_service_url` and `load_balancer_name` in configuration file, and set `load_balancer_name` to empty for single server and a valid algorithm for a cluster. +If `load_balancer_name` is nullptr or empty, this Init() is just the one for connecting single server and `naming_service_url` should be "ip:port" or "host:port" of the server. Thus you can unify initialization of all channels with this Init(). For example, you can put values of `naming_service_url` and `load_balancer_name` in configuration file, and set `load_balancer_name` to empty for single server and a valid algorithm for a cluster. ## Naming Service @@ -206,7 +206,7 @@ struct ServerNode { ``` The most common usage is filtering by server tags. -Customized filter is set to ChannelOptions to take effects. NULL by default means not filter. +Customized filter is set to ChannelOptions to take effects. nullptr by default means not filter. ```c++ class MyNamingServiceFilter : public brpc::NamingServiceFilter { @@ -306,7 +306,7 @@ Or even: ```c++ XXX_Stub(&channel).some_method(controller, request, response, done); ``` -A exception is http/h2 client, which is not related to protobuf much. Call CallMethod directly to make a http call, setting all parameters to NULL except for `Controller` and `done`, check [Access http/h2](http_client.md) for details. +A exception is http/h2 client, which is not related to protobuf much. Call CallMethod directly to make a http call, setting all parameters to nullptr except for `Controller` and `done`, check [Access http/h2](http_client.md) for details. ## Synchronous call @@ -321,7 +321,7 @@ XXX_Stub stub(&channel); request.set_foo(...); cntl.set_timeout_ms(...); -stub.some_method(&cntl, &request, &response, NULL); +stub.some_method(&cntl, &request, &response, nullptr); if (cntl.Failed()) { // RPC failed. fields in response are undefined, don't use. } else { diff --git a/docs/en/combo_channel.md b/docs/en/combo_channel.md index ab68188fe2..3b966569e6 100644 --- a/docs/en/combo_channel.md +++ b/docs/en/combo_channel.md @@ -48,7 +48,7 @@ Calling ` AddChannel` during a RPC over `ParallelChannel` is **NOT thread safe** ## CallMapper -This class converts RPCs to `ParallelChannel` to the ones to `sub channel`. If `call_mapper` is NULL, requests to the sub channel is just the ones to `ParallelChannel`, and responses are created by calling `New()` on the responses to `ParallelChannel`. `call_mapper` is deleted when `ParallelChannel` destructs. Due to the reference counting inside, one `call_mapper` can be associated with multiple sub channels. +This class converts RPCs to `ParallelChannel` to the ones to `sub channel`. If `call_mapper` is nullptr, requests to the sub channel is just the ones to `ParallelChannel`, and responses are created by calling `New()` on the responses to `ParallelChannel`. `call_mapper` is deleted when `ParallelChannel` destructs. Due to the reference counting inside, one `call_mapper` can be associated with multiple sub channels. ```c++ class CallMapper { @@ -78,7 +78,7 @@ The returned `SubCall` configures the calls to the corresponding sub channel and Common implementations of `Map()` are listed below: -- Broadcast the request. This is also the behavior when `call_mapper` is NULL: +- Broadcast the request. This is also the behavior when `call_mapper` is nullptr: ```c++ class Broadcaster : public CallMapper { @@ -147,7 +147,7 @@ Note: Modifying `ClientSettings` configurations (such as timeout and retries) is ## ResponseMerger -`response_merger` merges responses from all sub channels into one for the `ParallelChannel`. When it's NULL, `response->MergeFrom(*sub_response)` is used instead, whose behavior can be summarized as "merge repeated fields and overwrite the rest". If you need more complex behavior, implement `ResponseMerger`. Multiple `response_merger` are called one by one to merge sub responses so that you do not need to consider the race conditions between merging multiple responses simultaneously. The object is deleted when `ParallelChannel ` destructs. Due to the reference counting inside, `response_merger ` can be associated with multiple sub channels. +`response_merger` merges responses from all sub channels into one for the `ParallelChannel`. When it's nullptr, `response->MergeFrom(*sub_response)` is used instead, whose behavior can be summarized as "merge repeated fields and overwrite the rest". If you need more complex behavior, implement `ResponseMerger`. Multiple `response_merger` are called one by one to merge sub responses so that you do not need to consider the race conditions between merging multiple responses simultaneously. The object is deleted when `ParallelChannel ` destructs. Due to the reference counting inside, `response_merger ` can be associated with multiple sub channels. Possible values of `Result` are: @@ -162,13 +162,13 @@ Sometimes users may need to know the details around sub calls. `Controller.sub(i ```c++ // Get the controllers for accessing sub channels in combo channels. // Ordinary channel: -// sub_count() is 0 and sub() is always NULL. +// sub_count() is 0 and sub() is always nullptr. // ParallelChannel/PartitionChannel: // sub_count() is #sub-channels and sub(i) is the controller for // accessing i-th sub channel inside ParallelChannel, if i is outside -// [0, sub_count() - 1], sub(i) is NULL. -// NOTE: You must test sub() against NULL, ALWAYS. Even if i is inside -// range, sub(i) can still be NULL: +// [0, sub_count() - 1], sub(i) is nullptr. +// NOTE: You must test sub() against nullptr, ALWAYS. Even if i is inside +// range, sub(i) can still be nullptr: // * the rpc call may fail and terminate before accessing the sub channel // * the sub channel was skipped // SelectiveChannel/DynamicPartitionChannel: @@ -217,8 +217,8 @@ After successful initialization, add sub channels with `AddChannel`. ```c++ // The second parameter ChannelHandle is used to delete sub channel, -// which can be NULL if this isn't necessary. -if (schan.AddChannel(sub_channel, NULL/*ChannelHandle*/) != 0) { +// which can be nullptr if this isn't necessary. +if (schan.AddChannel(sub_channel, nullptr/*ChannelHandle*/) != 0) { LOG(ERROR) << "Fail to add sub_channel"; return -1; } @@ -228,7 +228,7 @@ Note that: - Unlike `ParallelChannel`, `SelectiveChannel::AddChannel` can be called at any time, even if a RPC over the SelectiveChannel is going on. (newly added channels take effects at the next RPC). - `SelectiveChannel` always owns sub channels, which is different from `ParallelChannel`'s configurable ownership. -- If the second parameter to `AddChannel` is not NULL, it's filled with a value typed `brpc::SelectiveChannel::ChannelHandle`, which can be used as the parameter to `RemoveAndDestroyChannel` to remove and destroy a channel dynamically. +- If the second parameter to `AddChannel` is not nullptr, it's filled with a value typed `brpc::SelectiveChannel::ChannelHandle`, which can be used as the parameter to `RemoveAndDestroyChannel` to remove and destroy a channel dynamically. - `SelectiveChannel` overrides timeouts in sub channels. For example, having timeout set to 100ms for a sub channel and 500ms for `SelectiveChannel`, the actual timeout is 500ms. `SelectiveChannel`s are accessed same as regular channels. @@ -256,18 +256,18 @@ if (channel.Init("c_murmurhash", &schan_options) != 0) { for (int i = 0; i < 3; ++i) { brpc::Channel* sub_channel = new brpc::Channel; - if (sub_channel->Init(ns_node_name[i], "rr", NULL) != 0) { + if (sub_channel->Init(ns_node_name[i], "rr", nullptr) != 0) { LOG(ERROR) << "Fail to init sub channel " << i; return -1; } - if (channel.AddChannel(sub_channel, NULL/*handle for removal*/) != 0) { + if (channel.AddChannel(sub_channel, nullptr/*handle for removal*/) != 0) { LOG(ERROR) << "Fail to add sub_channel to channel"; return -1; } } ... XXXService_Stub stub(&channel); -stub.FooMethod(&cntl, &request, &response, NULL); +stub.FooMethod(&cntl, &request, &response, nullptr); ... ``` @@ -295,7 +295,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); diff --git a/docs/en/couchbase_example.md b/docs/en/couchbase_example.md index 6748580827..1c3b1759b3 100644 --- a/docs/en/couchbase_example.md +++ b/docs/en/couchbase_example.md @@ -268,7 +268,7 @@ uint64_t cas; req.authenticateRequest("Administrator", "password"); // Execute the request -channel.CallMethod(NULL, &cntl, &req, &res, NULL); +channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); // Check controller status if (cntl.Failed()) { @@ -297,7 +297,7 @@ res.Clear(); req.selectBucketRequest("testing"); // Execute the request -channel.CallMethod(NULL, &cntl, &req, &res, NULL); +channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); if (cntl.Failed()) { LOG(ERROR) << "Unable to select bucket: " << cntl.ErrorText(); @@ -332,7 +332,7 @@ req.addRequest( ); // Execute the request -channel.CallMethod(NULL, &cntl, &req, &res, NULL); +channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); if (cntl.Failed()) { LOG(ERROR) << "Unable to add key-value: " << cntl.ErrorText(); @@ -361,7 +361,7 @@ res.Clear(); req.getRequest("sample_key"); // Execute the request -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: " << cntl.ErrorText(); @@ -393,7 +393,7 @@ res.Clear(); req.deleteRequest("sample_key"); // Execute the request -channel.CallMethod(NULL, &cntl, &req, &res, NULL); +channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); if (cntl.Failed()) { LOG(ERROR) << "Unable to delete key-value: " << cntl.ErrorText(); @@ -800,7 +800,7 @@ void* thread_worker(void* arg) { if (!auth_result.success) { std::cout << "Thread " << args->thread_id << ": Auth failed - " << auth_result.error_message << std::endl; - return NULL; + return nullptr; } // Perform CRUD operations on default collection @@ -810,7 +810,7 @@ void* thread_worker(void* arg) { // Perform collection-scoped operations perform_crud_operations_collection(couchbase_ops, base_key, "my_collection", args->stats); - return NULL; + return nullptr; } ``` @@ -889,7 +889,7 @@ int main(int argc, char* argv[]) { thread_args[i].bucket_name = g_config.bucket_names[thread_args[i].bucket_id]; thread_args[i].stats = &g_stats.per_thread_stats[i]; - if (bthread_start_background(&threads[i], NULL, thread_worker, &thread_args[i]) != 0) { + if (bthread_start_background(&threads[i], nullptr, thread_worker, &thread_args[i]) != 0) { LOG(ERROR) << "Failed to create thread " << i; return -1; } @@ -897,7 +897,7 @@ int main(int argc, char* argv[]) { // Wait for all threads to complete for (int i = 0; i < NUM_THREADS; ++i) { - bthread_join(threads[i], NULL); + bthread_join(threads[i], nullptr); } // Aggregate and display statistics @@ -931,7 +931,7 @@ void* shared_object_thread_worker(void *arg) { // Small delay between operations bthread_usleep(10000); // 10ms } - return NULL; + return nullptr; } // Main function demonstrates shared instance pattern @@ -967,7 +967,7 @@ int main_shared_demo() { // Start all threads using shared instance for (int i = 0; i < NUM_THREADS; ++i) { - if (bthread_start_background(&threads[i], NULL, shared_object_thread_worker, &args[i]) != 0) { + 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; } @@ -975,7 +975,7 @@ int main_shared_demo() { // Wait for all threads to complete 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; diff --git a/docs/en/error_code.md b/docs/en/error_code.md index db9260965d..a9a0e4869c 100644 --- a/docs/en/error_code.md +++ b/docs/en/error_code.md @@ -64,7 +64,7 @@ Note that `strerror` and `strerror_r` do not recognize error codes defined by `B ```c++ errno = ESTOP; printf("Describe errno: %m\n"); // [Wrong] Describe errno: Unknown error -114 -printf("Describe errno: %s\n", strerror_r(errno, NULL, 0)); // [Wrong] Describe errno: Unknown error -114 +printf("Describe errno: %s\n", strerror_r(errno, nullptr, 0)); // [Wrong] Describe errno: Unknown error -114 printf("Describe errno: %s\n", berror()); // [Correct] Describe errno: the thread is stopping printf("Describe errno: %s\n", berror(errno)); // [Correct] Describe errno: the thread is stopping ``` diff --git a/docs/en/http_client.md b/docs/en/http_client.md index 6c64431c34..95d664ae39 100644 --- a/docs/en/http_client.md +++ b/docs/en/http_client.md @@ -32,10 +32,10 @@ http/h2 channel also support BNS address or other naming services. ```c++ brpc::Controller cntl; cntl.http_request().uri() = "www.baidu.com/index.html"; // Request URL -channel.CallMethod(NULL, &cntl, NULL, NULL, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr/*done*/); ``` -http/h2 does not relate to protobuf much, thus all parameters of `CallMethod` are NULL except `Controller` and `done`. Issue asynchronous RPC with non-NULL `done`. +http/h2 does not relate to protobuf much, thus all parameters of `CallMethod` are nullptr except `Controller` and `done`. Issue asynchronous RPC with non-nullptr `done`. `cntl.response_attachment()` is body of the http/h2 response and typed `butil::IOBuf`. `IOBuf` can be converted to `std::string` by `to_string()`, which needs to allocate memory and copy all data. If performance is important, the code should consider supporting `IOBuf` directly rather than requiring continuous memory. @@ -48,7 +48,7 @@ brpc::Controller cntl; cntl.http_request().uri() = "..."; // Request URL cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"hello world!\"}"); -channel.CallMethod(NULL, &cntl, NULL, NULL, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr/*done*/); ``` If the body needs a lot of printing to build, consider using `butil::IOBufBuilder`, which has same interfaces as `std::ostringstream`, probably simpler and more efficient than c-style printf when lots of objects need to be printed. @@ -60,7 +60,7 @@ cntl.http_request().set_method(brpc::HTTP_METHOD_POST); butil::IOBufBuilder os; os << "A lot of printing" << printable_objects << ...; os.move_to(cntl.request_attachment()); -channel.CallMethod(NULL, &cntl, NULL, NULL, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr/*done*/); ``` # Change HTTP version @@ -127,7 +127,7 @@ Take http request as an example (similar with http response), common operations Access an HTTP header named `Foo` ```c++ -const std::string* value = cntl->http_request().GetHeader("Foo"); // NULL when not exist +const std::string* value = cntl->http_request().GetHeader("Foo"); // nullptr when not exist ``` Set an HTTP header named `Foo` @@ -137,7 +137,7 @@ cntl->http_request().SetHeader("Foo", "value"); Access a query named `Foo` ```c++ -const std::string* value = cntl->http_request().uri().GetQuery("Foo"); // NULL when not exist +const std::string* value = cntl->http_request().uri().GetQuery("Foo"); // nullptr when not exist ``` Set a query named `Foo` @@ -202,7 +202,7 @@ brpc does not decompress bodies of responses automatically due to universality. #include ... const std::string* encoding = cntl->http_response().GetHeader("Content-Encoding"); -if (encoding != NULL && *encoding == "gzip") { +if (encoding != nullptr && *encoding == "gzip") { butil::IOBuf uncompressed; if (!brpc::policy::GzipDecompress(cntl->response_attachment(), &uncompressed)) { LOG(ERROR) << "Fail to un-gzip response body"; diff --git a/docs/en/http_service.md b/docs/en/http_service.md index bf080ecb14..601dedd542 100644 --- a/docs/en/http_service.md +++ b/docs/en/http_service.md @@ -213,7 +213,7 @@ Query strings are also key/value pairs. Differences between HTTP headers and que ```c++ // Get value for header "User-Agent" (case insensitive) const std::string* user_agent_str = cntl->http_request().GetHeader("User-Agent"); -if (user_agent_str != NULL) { // has the header +if (user_agent_str != nullptr) { // has the header LOG(TRACE) << "User-Agent is " << *user_agent_str; } ... @@ -273,7 +273,7 @@ As mentioned in above [HTTP headers](#http-headers), query strings are interpret ```c++ const std::string* time_value = cntl->http_request().uri().GetQuery("time"); -if (time_value != NULL) { // the query string is present +if (time_value != nullptr) { // the query string is present LOG(TRACE) << "time = " << *time_value; } @@ -307,7 +307,7 @@ Due to generality, brpc does not decompress request bodies automatically, but us #include ... const std::string* encoding = cntl->http_request().GetHeader("Content-Encoding"); -if (encoding != NULL && *encoding == "gzip") { +if (encoding != nullptr && *encoding == "gzip") { butil::IOBuf uncompressed; if (!brpc::policy::GzipDecompress(cntl->request_attachment(), &uncompressed)) { LOG(ERROR) << "Fail to un-gzip request body"; diff --git a/docs/en/memcache_client.md b/docs/en/memcache_client.md index c65114cf03..8cdbde6bcd 100644 --- a/docs/en/memcache_client.md +++ b/docs/en/memcache_client.md @@ -41,12 +41,12 @@ if (!request.Set("hello", "world", 0xdeadbeef/*flags*/, 10/*expiring seconds*/, LOG(FATAL) << "Fail to SET request"; return -1; } -channel.CallMethod(NULL, &cntl, &request, &response, NULL/*done*/); +channel.CallMethod(nullptr, &cntl, &request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(FATAL) << "Fail to access memcached, " << cntl.ErrorText(); return -1; } -if (!response.PopSet(NULL)) { +if (!response.PopSet(nullptr)) { LOG(FATAL) << "Fail to SET memcached, " << response.LastError(); return -1; } @@ -55,7 +55,7 @@ if (!response.PopSet(NULL)) { Notes on above code: -- The class of the request must be `MemcacheRequest`, response must be `MemcacheResponse`, otherwise `CallMethod` fails. `stub` is not necessary, just call `channel.CallMethod` with `method` to NULL. +- The class of the request must be `MemcacheRequest`, response must be `MemcacheResponse`, otherwise `CallMethod` fails. `stub` is not necessary, just call `channel.CallMethod` with `method` to nullptr. - Call `request.XXX()` to add an operation, where `XXX` is `Set` in this example. Multiple operations inside a request are sent to a memcached server together (often referred to as "pipeline mode"). - call `response.PopXXX()` to pop result of an operation from the response, where `XXX` is `Set` in this example. true is returned on success, and false otherwise in which case use `response.LastError()` to get the error message. `XXX` must match the corresponding operation in the request, otherwise the pop is rejected. In above example, a `PopGet` would fail with the error message of "not a GET response". - Results of `Pop` are independent from the RPC result. Even if "a value cannot be put into the memcached", the RPC may still be successful. RPC failure means things like broken connection, timeout etc. If the business logic requires the memcache operations to be successful, you should test successfulness of both RPC and `PopXXX`. diff --git a/docs/en/new_protocol.md b/docs/en/new_protocol.md index 4f6d358aa6..23815933e2 100644 --- a/docs/en/new_protocol.md +++ b/docs/en/new_protocol.md @@ -67,7 +67,7 @@ typedef ParseResult (*Parse)(butil::IOBuf* source, Socket *socket, bool read_eof ``` This function is used to cut messages from source. Client side and server side must share the same parse function. The returned message will be passed to `process_request`(server side) or `process_response`(client side). -Argument: source is the binary content from remote side, socket is the corresponding connection, read_eof is true iff the connection is closed by remote, arg is a pointer to the corresponding server in server client and NULL in client side. +Argument: source is the binary content from remote side, socket is the corresponding connection, read_eof is true iff the connection is closed by remote, arg is a pointer to the corresponding server in server client and nullptr in client side. ParseResult could be an error or a cut message, its possible value contains: @@ -94,7 +94,7 @@ typedef int (*PackRequest)(butil::IOBuf* msg, const butil::IOBuf& request_buf, const Authenticator* auth); ``` -This function is used to pack request_buf into msg, which is called every time before sending messages to server(including retrying). When auth is not NULL, authentication information is also needed to be packed. Return 0 if succeed, otherwise -1. +This function is used to pack request_buf into msg, which is called every time before sending messages to server(including retrying). When auth is not nullptr, authentication information is also needed to be packed. Return 0 if succeed, otherwise -1. ### process_request ```c++ @@ -112,7 +112,7 @@ This function is used to parse message response in client side that client must ```c++ typedef bool (*Verify)(const InputMessageBase* msg); ``` -This function is used to authenticate connections, it is called when the first message is received. It is must be implemented by servers that need authentication, otherwise the function pointer can be NULL. Return true if succeed, otherwise false. +This function is used to authenticate connections, it is called when the first message is received. It is must be implemented by servers that need authentication, otherwise the function pointer can be nullptr. Return true if succeed, otherwise false. ### parse_server_address ```c++ diff --git a/docs/en/redis_client.md b/docs/en/redis_client.md index 2dbc6bfdfc..8638502e1e 100644 --- a/docs/en/redis_client.md +++ b/docs/en/redis_client.md @@ -42,7 +42,7 @@ brpc::RedisRequest set_request; brpc::RedisResponse response; brpc::Controller cntl; set_request.AddCommand("SET %s %d", my_key.c_str(), my_number); -redis_channel.CallMethod(NULL, &cntl, &set_request, &response, NULL/*done*/); +redis_channel.CallMethod(nullptr, &cntl, &set_request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(ERROR) << "Fail to access redis-server"; return -1; @@ -63,7 +63,7 @@ brpc::RedisRequest incr_request; incr_request.AddCommand("INCR %s", my_key.c_str()); response.Clear(); cntl.Reset(); -redis_channel.CallMethod(NULL, &cntl, &incr_request, &response, NULL/*done*/); +redis_channel.CallMethod(nullptr, &cntl, &incr_request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(ERROR) << "Fail to access redis-server"; return -1; @@ -88,7 +88,7 @@ request.AddCommand("INCR counter1"); request.AddCommand("DECR counter1"); request.AddCommand("INCRBY counter1 10"); request.AddCommand("DECRBY counter1 20"); -redis_channel.CallMethod(NULL, &cntl, &request, &response, NULL/*done*/); +redis_channel.CallMethod(nullptr, &cntl, &request, &response, nullptr/*done*/); if (cntl.Failed()) { LOG(ERROR) << "Fail to access redis-server"; return -1; diff --git a/docs/en/server.md b/docs/en/server.md index b7edd64701..80806db583 100644 --- a/docs/en/server.md +++ b/docs/en/server.md @@ -122,13 +122,13 @@ public: // Constructed with a closure which will be Run() inside dtor. explicit ClosureGuard(google::protobuf::Closure* done); - // Call Run() of internal closure if it's not NULL. + // Call Run() of internal closure if it's not nullptr. ~ClosureGuard(); - // Call Run() of internal closure if it's not NULL and set it to `done'. + // Call Run() of internal closure if it's not nullptr and set it to `done'. void reset(google::protobuf::Closure* done); - // Set internal closure to NULL and return the one before set. + // Set internal closure to nullptr and return the one before set. google::protobuf::Closure* release(); }; ``` @@ -214,7 +214,7 @@ int Start(const char *ip_str, PortRange port_range, const ServerOptions *opt); "localhost:9000", "cq01-cos-dev00.cq01:8000", "127.0.0.1:7000" are valid `ip_and_port_str`. -All parameters take default values if `options` is NULL. If you need non-default values, code as follows: +All parameters take default values if `options` is nullptr. If you need non-default values, code as follows: ```c++ brpc::ServerOptions options; // with default values @@ -725,7 +725,7 @@ Searching services inside Baidu use [thread-local storage](https://en.wikipedia. A session-local data is bound to a **server-side RPC**: from entering CallMethod of the service, to calling the server-side done->Run(), no matter the service is synchronous or asynchronous. All session-local data are reused as much as possible and not deleted before stopping the server. -After setting ServerOptions.session_local_data_factory, call Controller.session_local_data() to get a session-local data. If ServerOptions.session_local_data_factory is unset, Controller.session_local_data() always returns NULL. +After setting ServerOptions.session_local_data_factory, call Controller.session_local_data() to get a session-local data. If ServerOptions.session_local_data_factory is unset, Controller.session_local_data() always returns nullptr. If ServerOptions.reserved_session_local_data is greater than 0, Server creates so many data before serving. @@ -750,7 +750,7 @@ public: // Get the session-local data which is created by ServerOptions.session_local_data_factory // and reused between different RPC. MySessionLocalData* sd = static_cast(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"); return; } @@ -761,9 +761,9 @@ public: struct ServerOptions { ... // The factory to create/destroy data attached to each RPC session. - // If this field is NULL, Controller::session_local_data() is always NULL. + // If this field is nullptr, Controller::session_local_data() is always nullptr. // NOT owned by Server and must be valid when Server is running. - // Default: NULL + // Default: nullptr const DataFactory* session_local_data_factory; // Prepare so many session-local data before server starts, so that calls @@ -807,7 +807,7 @@ int main(int argc, char* argv[]) { A server-thread-local is bound to **a call to service's CallMethod**, from entering service's CallMethod, to leaving the method. All server-thread-local data are reused as much as possible and will not be deleted before stopping the server. server-thread-local is implemented as a special bthread-local. -After setting ServerOptions.thread_local_data_factory, call brpc::thread_local_data() to get a thread-local. If ServerOptions.thread_local_data_factory is unset, brpc::thread_local_data() always returns NULL. +After setting ServerOptions.thread_local_data_factory, call brpc::thread_local_data() to get a thread-local. If ServerOptions.thread_local_data_factory is unset, brpc::thread_local_data() always returns nullptr. If ServerOptions.reserved_thread_local_data is greater than 0, Server creates so many data before serving. @@ -839,7 +839,7 @@ public: // and reused between different threads. // "tls" is short for "thread local storage". MyThreadLocalData* tls = static_cast(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"); return; @@ -852,9 +852,9 @@ struct ServerOptions { ... // The factory to create/destroy data attached to each searching thread // in server. - // If this field is NULL, brpc::thread_local_data() is always NULL. + // If this field is nullptr, brpc::thread_local_data() is always nullptr. // NOT owned by Server and must be valid when Server is running. - // Default: NULL + // Default: nullptr const DataFactory* thread_local_data_factory; // Prepare so many thread-local data before server starts, so that calls @@ -907,9 +907,9 @@ Since brpc creates a bthread for each request, the bthread-local in the server b ```c++ // Create a key value identifying a slot in a thread-specific data area. // Each thread maintains a distinct thread-specific data area. -// `destructor', if non-NULL, is called with the value associated to that key +// `destructor', if non-nullptr, is called with the value associated to that key // when the key is destroyed. `destructor' is not called if the value -// associated is NULL when the key is destroyed. +// associated is nullptr when the key is destroyed. // Returns 0 on success, error code otherwise. extern int bthread_key_create(bthread_key_t* key, void (*destructor)(void* data)); @@ -937,8 +937,8 @@ extern int bthread_key_delete(bthread_key_t key); extern int bthread_setspecific(bthread_key_t key, void* data); // Return current value of the thread-specific slot identified by `key'. -// If bthread_setspecific() had not been called in the thread, return NULL. -// If the key is invalid or deleted, return NULL. +// If bthread_setspecific() had not been called in the thread, return nullptr. +// If the key is invalid or deleted, return nullptr. extern void* bthread_getspecific(bthread_key_t key); ``` @@ -946,7 +946,7 @@ extern void* bthread_getspecific(bthread_key_t key); Create a bthread_key_t which represents a kind of bthread-local variable. -Use bthread_[get|set]specific to get and set bthread-local variables. First-time access to a bthread-local variable from a bthread returns NULL. +Use bthread_[get|set]specific to get and set bthread-local variables. First-time access to a bthread-local variable from a bthread returns nullptr. Delete a bthread_key_t after no thread is using bthread-local associated with the key. If a bthread_key_t is deleted during usage, related bthread-local data are leaked. @@ -965,7 +965,7 @@ if (bthread_key_create(&tls_key, my_data_destructor) != 0) { ```c++ // in some thread ... MyThreadLocalData* tls = static_cast(bthread_getspecific(tls_key)); -if (tls == NULL) { // First call to bthread_getspecific (and before any bthread_setspecific) returns NULL +if (tls == nullptr) { // First call to bthread_getspecific (and before any bthread_setspecific) returns nullptr tls = new MyThreadLocalData; // Create thread-local data on demand. CHECK_EQ(0, bthread_setspecific(tls_key, tls)); // set the data so that next time bthread_getspecific in the thread returns the data. } @@ -1005,7 +1005,7 @@ public: // pthread_getspecific -> bthread_getspecific // pthread_setspecific -> bthread_setspecific MyThreadLocalData* tls2 = static_cast(bthread_getspecific(_tls2_key)); - if (tls2 == NULL) { + if (tls2 == nullptr) { tls2 = new MyThreadLocalData; CHECK_EQ(0, bthread_setspecific(_tls2_key, tls2)); } diff --git a/docs/en/streaming_rpc.md b/docs/en/streaming_rpc.md index 7a41c24dc8..e5e526a757 100644 --- a/docs/en/streaming_rpc.md +++ b/docs/en/streaming_rpc.md @@ -46,23 +46,23 @@ struct StreamOptions // default: 128 size_t messages_in_batch; - // Handle input message, if handler is NULL, the remote side is not allowed to + // Handle input message, if handler is nullptr, the remote side is not allowed to // write any message, who will get EBADF on writing - // default: NULL + // default: nullptr StreamInputHandler* handler; }; // [Called at the client side] // Create a Stream at client-side along with the |cntl|, which will be connected // when receiving the response with a Stream from server-side. If |options| is -// NULL, the Stream will be created with default options +// nullptr, the Stream will be created with default options // Return 0 on success, -1 otherwise int StreamCreate(StreamId* request_stream, Controller &cntl, const StreamOptions* options); // [Called at the client side for creating multiple streams] // Create streams at client-side along with the |cntl|, which will be connected // when receiving the response with streams from server-side. If |options| is -// NULL, the stream will be created with default options +// nullptr, the stream will be created with default options // Return 0 on success, -1 otherwise int StreamCreate(StreamIds& request_streams, int request_stream_size, Controller& cntl, const StreamOptions* options); @@ -131,7 +131,7 @@ When the amount of unacknowledged data reaches the limit, the `Write` operation // Wait until the pending buffer size is less than |max_buf_size| or error occurs // Returns 0 on success, errno otherwise // Errno: -// - ETIMEDOUT: when |due_time| is not NULL and time expired this +// - ETIMEDOUT: when |due_time| is not nullptr and time expired this // - EINVAL: the Stream was close during waiting int StreamWait(StreamId stream_id, const timespec* due_time); diff --git a/docs/en/thrift.md b/docs/en/thrift.md index d57f654d6f..06bc0cd82b 100755 --- a/docs/en/thrift.md +++ b/docs/en/thrift.md @@ -70,7 +70,7 @@ example::EchoRequest req; example::EchoResponse res; req.data = "hello"; -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(); return -1;