github-actions[bot] commented on code in PR #14063:
URL: https://github.com/apache/doris/pull/14063#discussion_r1064164750
##########
be/src/util/brpc_client_cache.h:
##########
@@ -54,13 +54,18 @@ class BrpcClientCache {
}
#else
std::shared_ptr<T> get_client(const TNetworkAddress& taddr) {
- std::string host_port = fmt::format("{}:{}", taddr.hostname,
taddr.port);
- return get_client(host_port);
+ return get_client(taddr.hostname, taddr.port);
}
#endif
std::shared_ptr<T> get_client(const std::string& host, int port) {
- std::string host_port = fmt::format("{}:{}", host, port);
+ std::string host_port;
+ //if host is an ipv6 address and not starts with Bracket
+ if (host.find(":") != std::string::npos && host[0] != '[') {
Review Comment:
warning: 'find' called with a string literal consisting of a single
character; consider using the more effective overload accepting a character
[performance-faster-string-find]
```suggestion
if (host.find(':') != std::string::npos && host[0] != '[') {
```
##########
be/src/util/network_util.cpp:
##########
@@ -183,4 +196,23 @@
return Status::OK();
}
+std::string get_host_port(const std::string& host, int port) {
+ std::stringstream ss;
+ if (host.find(":") == std::string::npos) {
Review Comment:
warning: 'find' called with a string literal consisting of a single
character; consider using the more effective overload accepting a character
[performance-faster-string-find]
```suggestion
if (host.find(':') == std::string::npos) {
```
##########
be/test/util/cidr_test.cpp:
##########
@@ -52,6 +52,16 @@ TEST(CIDR, contains) {
EXPECT_TRUE(cidr.reset("192.168.17.0/16"));
EXPECT_TRUE(cidr.contains("192.168.88.99"));
Review Comment:
warning: no matching member function for call to 'contains'
[clang-diagnostic-error]
```cpp
EXPECT_TRUE(cidr.contains("192.168.88.99"));
^
```
**thirdparty/installed/include/gtest/gtest.h:1981:** expanded from macro
'EXPECT_TRUE'
```cpp
#define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition)
^
```
**thirdparty/installed/include/gtest/gtest.h:1965:** expanded from macro
'GTEST_EXPECT_TRUE'
```cpp
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
^
```
**thirdparty/installed/include/gtest/internal/gtest-internal.h:1501:**
expanded from macro 'GTEST_TEST_BOOLEAN_'
```cpp
::testing::AssertionResult(expression)) \
^
```
**be/src/util/cidr.h:34:** candidate function not viable: no known
conversion from 'const char[14]' to 'uint32_t' (aka 'unsigned int') for 1st
argument
```cpp
bool contains(uint32_t ip_int);
^
```
**be/src/util/cidr.h:31:** candidate function not viable: no known
conversion from 'const char[14]' to 'const doris::CIDR' for 1st argument
```cpp
bool contains(const CIDR& ip) const;
^
```
##########
be/src/util/network_util.cpp:
##########
@@ -39,22 +39,38 @@
namespace doris {
InetAddress::InetAddress(struct sockaddr* addr) {
- this->addr = *(struct sockaddr_in*)addr;
+ this->addr = *(struct sockaddr_storage*)addr;
}
-bool InetAddress::is_address_v4() const {
- return addr.sin_family == AF_INET;
+bool InetAddress::is_loopback() {
+ if (addr.ss_family == AF_INET) {
+ in_addr_t s_addr = ((struct sockaddr_in*)&addr)->sin_addr.s_addr;
+ return (ntohl(s_addr) & 0xFF000000) == 0x7F000000;
+ } else if (addr.ss_family == AF_INET6) {
+ struct in6_addr in6_addr = ((struct sockaddr_in6*)&addr)->sin6_addr;
+ return IN6_IS_ADDR_LOOPBACK(&in6_addr);
+ } else {
+ LOG(WARNING) << "unknow address";
+ return false;
+ }
}
-bool InetAddress::is_loopback_v4() {
- in_addr_t s_addr = addr.sin_addr.s_addr;
- return (ntohl(s_addr) & 0xFF000000) == 0x7F000000;
+std::string InetAddress::get_host_address() {
+ if (addr.ss_family == AF_INET) {
+ char addr_buf[INET_ADDRSTRLEN];
+ inet_ntop(AF_INET, &(((struct sockaddr_in*)&addr)->sin_addr),
addr_buf, INET_ADDRSTRLEN);
+ return std::string(addr_buf);
+ } else if (addr.ss_family == AF_INET6) {
+ char addr_buf[INET6_ADDRSTRLEN];
+ inet_ntop(AF_INET6, &(((struct sockaddr_in6*)&addr)->sin6_addr),
addr_buf,
+ INET6_ADDRSTRLEN);
+ return std::string(addr_buf);
+ } else {
+ return std::string {"unknown address"};
+ }
}
-
-std::string InetAddress::get_host_address_v4() {
- char addr_buf[INET_ADDRSTRLEN];
- inet_ntop(AF_INET, &(addr.sin_addr), addr_buf, INET_ADDRSTRLEN);
- return std::string(addr_buf);
+bool InetAddress::is_ipv6() {
Review Comment:
warning: method 'is_ipv6' can be made const
[readability-make-member-function-const]
```suggestion
bool InetAddress::is_ipv6() const {
```
be/src/util/network_util.h:34:
```diff
- bool is_ipv6();
+ bool is_ipv6() const;
```
##########
be/test/util/cidr_test.cpp:
##########
@@ -52,6 +52,16 @@
EXPECT_TRUE(cidr.reset("192.168.17.0/16"));
EXPECT_TRUE(cidr.contains("192.168.88.99"));
EXPECT_FALSE(cidr.contains("192.2.88.99"));
Review Comment:
warning: no matching member function for call to 'contains'
[clang-diagnostic-error]
```cpp
EXPECT_FALSE(cidr.contains("192.2.88.99"));
^
```
**thirdparty/installed/include/gtest/gtest.h:1985:** expanded from macro
'EXPECT_FALSE'
```cpp
#define EXPECT_FALSE(condition) GTEST_EXPECT_FALSE(condition)
^
```
**thirdparty/installed/include/gtest/gtest.h:1968:** expanded from macro
'GTEST_EXPECT_FALSE'
```cpp
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
^
```
**thirdparty/installed/include/gtest/internal/gtest-internal.h:1501:**
expanded from macro 'GTEST_TEST_BOOLEAN_'
```cpp
::testing::AssertionResult(expression)) \
^
```
**be/src/util/cidr.h:34:** candidate function not viable: no known
conversion from 'const char[12]' to 'uint32_t' (aka 'unsigned int') for 1st
argument
```cpp
bool contains(uint32_t ip_int);
^
```
**be/src/util/cidr.h:31:** candidate function not viable: no known
conversion from 'const char[12]' to 'const doris::CIDR' for 1st argument
```cpp
bool contains(const CIDR& ip) const;
^
```
##########
be/src/util/network_util.cpp:
##########
@@ -183,4 +196,23 @@
return Status::OK();
}
+std::string get_host_port(const std::string& host, int port) {
+ std::stringstream ss;
+ if (host.find(":") == std::string::npos) {
+ ss << host << ":" << port;
+ } else {
+ ss << "[" << host << "]"
+ << ":" << port;
+ }
+ return ss.str();
+}
+
+std::string get_brpc_http_url(const std::string& host, int port) {
+ if (host.find(":") != std::string::npos) {
Review Comment:
warning: 'find' called with a string literal consisting of a single
character; consider using the more effective overload accepting a character
[performance-faster-string-find]
```suggestion
if (host.find(':') != std::string::npos) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]