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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/brpc/details/controller_private_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ControllerPrivateAccessor {
}

void move_in_server_receiving_sock(SocketUniquePtr& ptr) {
CHECK(_cntl->_current_call.sending_sock == NULL);
CHECK(_cntl->_current_call.sending_sock == nullptr);
_cntl->_current_call.sending_sock.reset(ptr.release());
}

Expand Down
3 changes: 1 addition & 2 deletions src/brpc/details/has_epollrdhup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ static unsigned int check_epollrdhup() {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, (int*)fds) < 0) {
return 0;
}
epoll_event evt = { static_cast<uint32_t>(EPOLLIN | EPOLLRDHUP | EPOLLET),
{ NULL }};
epoll_event evt = { static_cast<uint32_t>(EPOLLIN | EPOLLRDHUP | EPOLLET), { nullptr }};
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &evt) < 0) {
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/brpc/details/health_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void* HealthCheckManager::AppCheck(void* arg) {
done->cntl.http_request().uri() = done->hc_option.health_check_path;
ControllerPrivateAccessor(&done->cntl).set_health_check_call();
done->last_check_time_ms = butil::cpuwide_time_ms();
done->channel.CallMethod(NULL, &done->cntl, NULL, NULL, done);
return NULL;
done->channel.CallMethod(nullptr, &done->cntl, nullptr, nullptr, done);
return nullptr;
}

void OnAppHealthCheckDone::Run() {
Expand Down Expand Up @@ -187,10 +187,10 @@ bool HealthCheckTask::OnTriggeringTask(timespec* next_abstime) {
}
}

// g_vars must not be NULL because it is newed at the creation of
// g_vars must not be nullptr because it is newed at the creation of
// first Socket. When g_vars is used, the socket is at health-checking
// state, which means the socket must be created and then g_vars can
// not be NULL.
// not be nullptr.
g_vars->nhealthcheck << 1;
int hc = 0;
if (ptr->_user) {
Expand Down
34 changes: 17 additions & 17 deletions src/brpc/details/hpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct IndexTableOptions {
IndexTableOptions()
: max_size(0)
, start_index(0)
, static_table(NULL)
, static_table(nullptr)
, static_table_size(0)
, need_indexes(false)
{}
Expand Down Expand Up @@ -83,7 +83,7 @@ DISALLOW_COPY_AND_ASSIGN(IndexTable);

const Header* HeaderAt(int index) const {
if (BAIDU_UNLIKELY(index < _start_index)) {
return NULL;
return nullptr;
}
return _header_queue.bottom(index - _start_index);
};
Expand Down Expand Up @@ -319,10 +319,10 @@ DISALLOW_COPY_AND_ASSIGN(HuffmanTree);

const HuffmanNode* node(NodeId id) const {
if (id == 0u) {
return NULL;
return nullptr;
}
if (id > _node_memory.size()) {
return NULL;
return nullptr;
}
return &_node_memory[id - 1];
}
Expand Down Expand Up @@ -386,7 +386,7 @@ DISALLOW_COPY_AND_ASSIGN(HuffmanEncoder);
_out->push_back(_partial_byte);
_partial_byte = 0;
_remain_bit = 0;
_out = NULL;
_out = nullptr;
++_out_bytes;
}

Expand Down Expand Up @@ -496,8 +496,8 @@ inline void EncodeInteger(butil::IOBufAppender* out, uint8_t msb,
}

// Static variables
static HuffmanTree* s_huffman_tree = NULL;
static IndexTable* s_static_table = NULL;
static HuffmanTree* s_huffman_tree = nullptr;
static IndexTable* s_static_table = nullptr;
static pthread_once_t s_create_once = PTHREAD_ONCE_INIT;

static void CreateStaticTableOrDie() {
Expand Down Expand Up @@ -530,7 +530,7 @@ static const size_t MAX_HPACK_INTEGER = 10 * 1024 * 1024ul;

inline ssize_t DecodeInteger(butil::IOBufBytesIterator& iter,
uint8_t prefix_size, uint32_t* value) {
if (iter == NULL) {
if (iter == nullptr) {
return 0; // No enough data
}
uint8_t first_byte = *iter;
Expand Down Expand Up @@ -615,7 +615,7 @@ inline void EncodeString(butil::IOBufAppender* out, const std::string& s,
}

inline ssize_t DecodeString(butil::IOBufBytesIterator& iter, std::string* out) {
if (iter == NULL) {
if (iter == nullptr) {
return 0;
}
const bool huffman = *iter & 0x80;
Expand All @@ -634,7 +634,7 @@ inline ssize_t DecodeString(butil::IOBufBytesIterator& iter, std::string* out) {
return in_bytes;
}
HuffmanDecoder d(out, s_huffman_tree);
for (; iter != NULL && length; ++iter, --length) {
for (; iter != nullptr && length; ++iter, --length) {
if (d.Decode(*iter) != 0) {
return -1;
}
Expand All @@ -646,19 +646,19 @@ inline ssize_t DecodeString(butil::IOBufBytesIterator& iter, std::string* out) {
}

HPacker::HPacker()
: _encode_table(NULL)
, _decode_table(NULL) {
: _encode_table(nullptr)
, _decode_table(nullptr) {
CreateStaticTableOnceOrDie();
}

HPacker::~HPacker() {
if (_encode_table) {
delete _encode_table;
_encode_table = NULL;
_encode_table = nullptr;
}
if (_decode_table) {
delete _decode_table;
_decode_table = NULL;
_decode_table = nullptr;
}
}

Expand Down Expand Up @@ -752,7 +752,7 @@ inline ssize_t HPacker::DecodeWithKnownPrefix(
}
if (index != 0) {
const Header* indexed_header = HeaderAt(index);
if (indexed_header == NULL) {
if (indexed_header == nullptr) {
LOG(ERROR) << "No header at index=" << index;
return -1;
}
Expand All @@ -776,7 +776,7 @@ inline ssize_t HPacker::DecodeWithKnownPrefix(
ssize_t HPacker::Decode(butil::IOBufBytesIterator& iter, Header* h) {
ssize_t skipped_bytes = 0;
decode_next:
if (iter == NULL) {
if (iter == nullptr) {
return 0;
}
const uint8_t first_byte = *iter;
Expand All @@ -799,7 +799,7 @@ ssize_t HPacker::Decode(butil::IOBufBytesIterator& iter, Header* h) {
return index_bytes;
}
const Header* indexed_header = HeaderAt(index);
if (indexed_header == NULL) {
if (indexed_header == nullptr) {
LOG(ERROR) << "No header at index=" << index;
return -1;
}
Expand Down
38 changes: 19 additions & 19 deletions src/brpc/details/http_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int HttpMessage::on_header_value(http_parser *parser,
}
if (FLAGS_http_verbose) {
butil::IOBufBuilder* vs = http_message->_vmsgbuilder.get();
if (vs == NULL) {
if (vs == nullptr) {
vs = new butil::IOBufBuilder;
http_message->_vmsgbuilder.reset(vs);
if (parser->type == HTTP_REQUEST) {
Expand Down Expand Up @@ -177,7 +177,7 @@ int HttpMessage::on_headers_complete(http_parser *parser) {
URI& uri = headers.uri();
if (uri._host.empty()) {
const std::string* host_header = headers.GetHeader("host");
if (host_header != NULL) {
if (host_header != nullptr) {
uri.SetHostAndPort(*host_header);
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ int HttpMessage::UnlockAndFlushToBodyReader(std::unique_lock<butil::Mutex>& mu)
butil::Status st = r->OnReadOnePart(blk.data(), blk.size());
if (!st.ok()) {
mu.lock();
_body_reader = NULL;
_body_reader = nullptr;
mu.unlock();
r->OnEndOfMessage(st);
return -1;
Expand Down Expand Up @@ -274,7 +274,7 @@ int HttpMessage::OnBody(const char *at, const size_t length) {
// the body is probably streaming data which is too long to print.
header().status_code() == HTTP_STATUS_OK) {
LOG(INFO) << '\n' << _vmsgbuilder->buf();
_vmsgbuilder.reset(NULL);
_vmsgbuilder.reset(nullptr);
} else {
if (_vbodylen < (size_t)FLAGS_http_verbose_max_body_length) {
int plen = std::min(length, (size_t)FLAGS_http_verbose_max_body_length
Expand All @@ -291,7 +291,7 @@ int HttpMessage::OnBody(const char *at, const size_t length) {
}
if (!_read_body_progressively) {
// Normal read.
if (NULL != _current_source_iobuf) {
if (nullptr != _current_source_iobuf) {
_current_source_iobuf->append_to(
&_body, length, _parsed_block_size + (at - _current_block_base));
} else {
Expand All @@ -302,7 +302,7 @@ int HttpMessage::OnBody(const char *at, const size_t length) {
// Progressive read.
std::unique_lock<butil::Mutex> mu(_body_mutex);
ProgressiveReader* r = _body_reader;
while (r == NULL) {
while (r == nullptr) {
// When _body is full, the sleep-waiting may block parse handler
// of the protocol. A more efficient solution is to remove the
// socket from epoll and add it back when the _body is not full,
Expand All @@ -328,7 +328,7 @@ int HttpMessage::OnBody(const char *at, const size_t length) {
return 0;
}
mu.lock();
_body_reader = NULL;
_body_reader = nullptr;
mu.unlock();
r->OnEndOfMessage(st);
return -1;
Expand All @@ -341,10 +341,10 @@ int HttpMessage::OnMessageComplete() {
- (size_t)FLAGS_http_verbose_max_body_length << " bytes>";
}
LOG(INFO) << '\n' << _vmsgbuilder->buf();
_vmsgbuilder.reset(NULL);
_vmsgbuilder.reset(nullptr);
}
_cur_header.clear();
_cur_value = NULL;
_cur_value = nullptr;
if (!_read_body_progressively) {
// Normal read.
_stage = HTTP_ON_MESSAGE_COMPLETE;
Expand All @@ -353,7 +353,7 @@ int HttpMessage::OnMessageComplete() {
// Progressive read.
std::unique_lock<butil::Mutex> mu(_body_mutex);
_stage = HTTP_ON_MESSAGE_COMPLETE;
if (_body_reader != NULL) {
if (_body_reader != nullptr) {
// Solve the case: SetBodyReader quit at ntry=MAX_TRY with non-empty
// _body and the remaining _body is just the last part.
// Make sure _body is emptied.
Expand All @@ -362,7 +362,7 @@ int HttpMessage::OnMessageComplete() {
}
mu.lock();
ProgressiveReader* r = _body_reader;
_body_reader = NULL;
_body_reader = nullptr;
mu.unlock();
r->OnEndOfMessage(butil::Status());
}
Expand All @@ -379,7 +379,7 @@ class FailAllRead : public ProgressiveReader {
void OnEndOfMessage(const butil::Status&) {}
};

static FailAllRead* s_fail_all_read = NULL;
static FailAllRead* s_fail_all_read = nullptr;
static pthread_once_t s_fail_all_read_once = PTHREAD_ONCE_INIT;
static void CreateFailAllRead() { s_fail_all_read = new FailAllRead; }

Expand All @@ -393,7 +393,7 @@ void HttpMessage::SetBodyReader(ProgressiveReader* r) {
int ntry = 0;
do {
std::unique_lock<butil::Mutex> mu(_body_mutex);
if (_body_reader != NULL) {
if (_body_reader != nullptr) {
mu.unlock();
return r->OnEndOfMessage(
butil::Status(EPERM, "SetBodyReader is called more than once"));
Expand Down Expand Up @@ -456,7 +456,7 @@ HttpMessage::HttpMessage(bool read_body_progressively,
HttpMessage::~HttpMessage() {
if (_body_reader) {
ProgressiveReader* saved_body_reader = _body_reader;
_body_reader = NULL;
_body_reader = nullptr;
// Successfully ended message is ended in OnMessageComplete() or
// SetBodyReader() and _body_reader should be null-ed. Non-null
// _body_reader here just means the socket is broken before completion
Expand Down Expand Up @@ -499,7 +499,7 @@ ssize_t HttpMessage::ParseFromIOBuf(const butil::IOBuf &buf) {
_parsed_block_size = 0;
_current_source_iobuf = &buf;
BRPC_SCOPE_EXIT {
_current_source_iobuf = NULL;
_current_source_iobuf = nullptr;
};
size_t nprocessed = 0;
for (size_t i = 0; i < buf.backing_block_num(); ++i) {
Expand Down Expand Up @@ -632,7 +632,7 @@ void MakeRawHttpRequest(butil::IOBuf* request,
//the request-target consists of only the host name and port number of
//the tunnel destination, separated by a colon. For example,
//Host: server.example.com:80
if (h->GetHeader("host") == NULL) {
if (h->GetHeader("host") == nullptr) {
os << "Host: ";
if (!uri.host().empty()) {
os << uri.host();
Expand All @@ -652,15 +652,15 @@ void MakeRawHttpRequest(butil::IOBuf* request,
it != h->HeaderEnd(); ++it) {
os << it->first << ": " << it->second << BRPC_CRLF;
}
if (h->GetHeader("Accept") == NULL) {
if (h->GetHeader("Accept") == nullptr) {
os << "Accept: */*" BRPC_CRLF;
}
// The fake "curl" user-agent may let servers return plain-text results.
if (h->GetHeader("User-Agent") == NULL) {
if (h->GetHeader("User-Agent") == nullptr) {
os << "User-Agent: brpc/1.0 curl/7.0" BRPC_CRLF;
}
const std::string& user_info = h->uri().user_info();
if (!user_info.empty() && h->GetHeader("Authorization") == NULL) {
if (!user_info.empty() && h->GetHeader("Authorization") == nullptr) {
// NOTE: just assume user_info is well formatted, namely
// "<user_name>:<password>". Users are very unlikely to add extra
// characters in this part and even if users did, most of them are
Expand Down
12 changes: 6 additions & 6 deletions src/brpc/details/http_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@ class HttpMessage {
// For mutual exclusion between on_body and SetBodyReader.
butil::Mutex _body_mutex;
// Read body progressively
ProgressiveReader* _body_reader{NULL};
ProgressiveReader* _body_reader{nullptr};
butil::IOBuf _body;
size_t _body_size{0};
bool _body_too_large{false};

// Store the IOBuf information in `ParseFromIOBuf'
// for later zero-copy usage in `OnBody'.
const butil::IOBuf* _current_source_iobuf{NULL};
const char* _current_block_base{NULL};
const butil::IOBuf* _current_source_iobuf{nullptr};
const char* _current_block_base{nullptr};
size_t _parsed_block_size{0};

// Parser related members
struct http_parser _parser;
std::string _cur_header;
std::string *_cur_value{NULL};
std::string *_cur_value{nullptr};

protected:
// Only valid when -http_verbose is on
Expand All @@ -141,15 +141,15 @@ std::ostream& operator<<(std::ostream& os, const http_parser& parser);
// Serialize a http request.
// header: may be modified in some cases
// remote_side: used when "Host" is absent
// content: could be NULL.
// content: could be nullptr.
void MakeRawHttpRequest(butil::IOBuf* request,
HttpHeader* header,
const butil::EndPoint& remote_side,
const butil::IOBuf* content);

// Serialize a http response.
// header: may be modified in some cases
// content: cleared after usage. could be NULL.
// content: cleared after usage. could be nullptr.
void MakeRawHttpResponse(butil::IOBuf* response,
HttpHeader* header,
butil::IOBuf* content);
Expand Down
4 changes: 2 additions & 2 deletions src/brpc/details/http_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ do { \
return (ER); \
} \
} \
FOR##_mark = NULL; \
FOR##_mark = nullptr; \
} \
} while (0)

Expand Down Expand Up @@ -2424,7 +2424,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,

if (u->field_set & (1 << UF_PORT)) {
/* Don't bother with endp; we've already validated the string */
unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, NULL, 10);
unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, nullptr, 10);

/* Ports have a max value of 2^16 */
if (v > 0xffff) {
Expand Down
Loading
Loading