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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cn/backup_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ channel.Init(..., &options);
| `window_size_seconds` | 10 | 滑动窗口宽度(秒),取值范围 [1, 3600] |
| `update_interval_seconds` | 5 | 缓存刷新间隔(秒),必须 >= 1 |

参数不合法时 `CreateRateLimitedBackupPolicy` 返回 `NULL`。
参数不合法时 `CreateRateLimitedBackupPolicy` 返回 `nullptr`。

### 使用自定义 BackupRequestPolicy

Expand Down
4 changes: 2 additions & 2 deletions docs/cn/bthread_or_not.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/cn/bvar_c++.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -634,7 +634,7 @@ static void get_username(std::ostream& os, void*) {
os << "unknown";
}
}
PassiveStatus<std::string> g_username("process_username", get_username, NULL);
PassiveStatus<std::string> g_username("process_username", get_username, nullptr);
```

# bvar::GFlag
Expand Down
12 changes: 6 additions & 6 deletions docs/cn/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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`置空,要连接服务集群时则设置一个有效的算法名称。

## 命名服务

Expand Down Expand Up @@ -208,7 +208,7 @@ struct ServerNode {
```
常见的业务策略如根据server的tag进行过滤。

自定义的过滤器配置在ChannelOptions中,默认为NULL(不过滤)。
自定义的过滤器配置在ChannelOptions中,默认为nullptr(不过滤)。

```c++
class MyNamingServiceFilter : public brpc::NamingServiceFilter {
Expand Down Expand Up @@ -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)。

## 同步访问

Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions docs/cn/combo_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -80,7 +80,7 @@ method/request/response:ParallelChannel.CallMethod()的参数。

常见的Map()实现有:

- 广播request。这也是call_mapper为NULL时的行为
- 广播request。这也是call_mapper为nullptr时的行为
```c++
class Broadcaster : public CallMapper {
public:
Expand Down Expand Up @@ -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: 成功合并。
Expand All @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
...
```

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions docs/cn/coroutine.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ brpc::experimental::Awaitable<int> RpcCall(brpc::Channel& channel) {

brpc::experimental::Awaitable<void> CoroutineMain(const char* server) {
brpc::Channel channel;
channel.Init(server, NULL);
channel.Init(server, nullptr);
// co_await会从Awaitable<int>得到int类型的返回值
int code = co_await RpcCall(channel);
printf("Rpc result:%d\n", code);
Expand Down Expand Up @@ -120,7 +120,7 @@ brpc::experimental::Awaitable<int> inplace_func() {
```cpp
brpc::experimental::Awaitable<void> CoroutineMain(const char* server) {
brpc::Channel channel;
channel.Init(server, NULL);
channel.Init(server, nullptr);
brpc::experimental::Awaitable<int> awaitable = RpcCall(channel);

int code = co_await awaitable;
Expand All @@ -141,7 +141,7 @@ brpc::experimental::Awaitable<void> CoroutineMain(const char* server) {

// co_await之前的逻辑,保持不变
brpc::Channel channel;
channel.Init(server, NULL);
channel.Init(server, nullptr);
brpc::experimental::Awaitable<int> awaitable = RpcCall(channel);

// co_await的逻辑,转成一个await_suspend的函数调用,传入一个callback函数
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/error_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
10 changes: 5 additions & 5 deletions docs/cn/execution_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,8 +172,8 @@ int execution_queue_execute(ExecutionQueueId<T> 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 <typename T>
int execution_queue_execute(ExecutionQueueId<T> id,
typename butil::add_const_reference<T>::type task,
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/flatmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions docs/cn/http_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,而不要求连续内存。

Expand All @@ -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更高。
Expand All @@ -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版本

Expand Down Expand Up @@ -126,15 +126,15 @@ 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++
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++
Expand Down Expand Up @@ -197,7 +197,7 @@ Notes on http header:
#include <brpc/policy/gzip_compress.h>
...
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";
Expand Down
6 changes: 3 additions & 3 deletions docs/cn/http_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
...
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -306,7 +306,7 @@ http服务常对http body进行压缩,可以有效减少网页的传输时间
#include <brpc/policy/gzip_compress.h>
...
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";
Expand Down
12 changes: 6 additions & 6 deletions docs/cn/mbvar_c++.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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<std::string>& labels_value);
};
```
Expand Down Expand Up @@ -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()) {}
Expand All @@ -480,15 +480,15 @@ public:

// Converts to `std::basic_string`.
explicit operator std::string() const {
if (NULL == _ptr) {
if (nullptr == _ptr) {
return {};
}
return {_ptr, size()};
}

// Converts to butil::StringPiece.
explicit operator butil::StringPiece() const {
if (NULL == _ptr) {
if (nullptr == _ptr) {
return {};
}
return {_ptr, size()};
Expand Down
Loading
Loading