You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/07/18 14:27:34 UTC
(kudu) branch master updated: [util] simplify DiagnosticSocket::SocketStateWildcard
This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 097e74480 [util] simplify DiagnosticSocket::SocketStateWildcard
097e74480 is described below
commit 097e74480cbcfc639188850375185f81dda243d2
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Jul 17 11:38:00 2025 -0700
[util] simplify DiagnosticSocket::SocketStateWildcard
Use std::array instead of std::vector for socket state wildcard.
This changelist doesn't contains any functional modifications.
Change-Id: Ifdfec2c75e997b5f539b849df51d2894afc399c4
Reviewed-on: http://gerrit.cloudera.org:8080/23184
Tested-by: Alexey Serbin <al...@apache.org>
Reviewed-by: KeDeng <kd...@gmail.com>
---
src/kudu/util/net/diagnostic_socket-test.cc | 2 +-
src/kudu/util/net/diagnostic_socket.cc | 11 +++++++----
src/kudu/util/net/diagnostic_socket.h | 13 ++++++++-----
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/kudu/util/net/diagnostic_socket-test.cc b/src/kudu/util/net/diagnostic_socket-test.cc
index 9f192a45f..6e407a3e2 100644
--- a/src/kudu/util/net/diagnostic_socket-test.cc
+++ b/src/kudu/util/net/diagnostic_socket-test.cc
@@ -100,7 +100,7 @@ TEST_F(DiagnosticSocketTest, SimplePattern) {
const auto& src_addr = listen_addr_;
const auto& dst_addr = Sockaddr::Wildcard();
- const vector<DiagnosticSocket::SocketState> socket_states{ DiagnosticSocket::SS_LISTEN };
+ const DiagnosticSocket::SocketStates socket_states{ DiagnosticSocket::SS_LISTEN };
DiagnosticSocket ds;
ASSERT_OK(ds.Init());
diff --git a/src/kudu/util/net/diagnostic_socket.cc b/src/kudu/util/net/diagnostic_socket.cc
index 22d461725..6b3e14f08 100644
--- a/src/kudu/util/net/diagnostic_socket.cc
+++ b/src/kudu/util/net/diagnostic_socket.cc
@@ -26,6 +26,7 @@
#include <sys/socket.h>
#include <unistd.h>
+#include <array>
#include <cerrno>
#include <ostream>
#include <string>
@@ -46,8 +47,8 @@ using strings::Substitute;
namespace kudu {
-const vector<DiagnosticSocket::SocketState>& DiagnosticSocket::SocketStateWildcard() {
- static const vector<DiagnosticSocket::SocketState> kSocketStateWildcard {
+const DiagnosticSocket::SocketStates& DiagnosticSocket::SocketStateWildcard() {
+ static constexpr const SocketStates kSocketStateWildcard {
SS_ESTABLISHED,
SS_SYN_SENT,
SS_SYN_RECV,
@@ -60,6 +61,7 @@ const vector<DiagnosticSocket::SocketState>& DiagnosticSocket::SocketStateWildca
SS_LISTEN,
SS_CLOSING,
};
+ static_assert(kSocketStateWildcard.size() == SocketState::SS_MAX);
return kSocketStateWildcard;
}
@@ -100,13 +102,14 @@ Status DiagnosticSocket::Close() {
Status DiagnosticSocket::Query(const Sockaddr& socket_src_addr,
const Sockaddr& socket_dst_addr,
- const vector<SocketState>& socket_states,
+ const SocketStates& matching_socket_states,
vector<TcpSocketInfo>* info) const {
DCHECK_GE(fd_, 0) << "requires calling Init() first";
DCHECK(info);
uint32_t socket_states_bitmask = 0;
- for (auto state : socket_states) {
+ for (auto state : matching_socket_states) {
+ DCHECK_LT(state, 8 * sizeof(decltype(socket_states_bitmask)));
socket_states_bitmask |= (1U << state);
}
diff --git a/src/kudu/util/net/diagnostic_socket.h b/src/kudu/util/net/diagnostic_socket.h
index 84ff6f293..c64b6951f 100644
--- a/src/kudu/util/net/diagnostic_socket.h
+++ b/src/kudu/util/net/diagnostic_socket.h
@@ -17,6 +17,7 @@
#pragma once
+#include <array>
#include <cstdint>
#include <vector>
@@ -42,7 +43,7 @@ class DiagnosticSocket final {
// of this class.
enum SocketState {
SS_UNKNOWN = 0,
- SS_ESTABLISHED,
+ SS_ESTABLISHED = 1,
SS_SYN_SENT,
SS_SYN_RECV,
SS_FIN_WAIT1,
@@ -53,9 +54,11 @@ class DiagnosticSocket final {
SS_LAST_ACK,
SS_LISTEN,
SS_CLOSING,
- SS_MAX,
+ SS_MAX = SS_CLOSING,
};
+ typedef std::array<SocketState, SocketState::SS_MAX> SocketStates;
+
// Diagnostic information on a TCP IPv4 socket. That's a subset of the
// information available via the netlink data structures.
//
@@ -72,8 +75,8 @@ class DiagnosticSocket final {
uint32_t tx_queue_size; // TX queue size
};
- // Return wildcard for all the available socket states.
- static const std::vector<SocketState>& SocketStateWildcard();
+ // Return wildcard for all valid socket states.
+ static const SocketStates& SocketStateWildcard();
// Construct an object.
DiagnosticSocket();
@@ -98,7 +101,7 @@ class DiagnosticSocket final {
// are supported.
Status Query(const Sockaddr& socket_src_addr,
const Sockaddr& socket_dst_addr,
- const std::vector<SocketState>& socket_states,
+ const SocketStates& matching_socket_states,
std::vector<TcpSocketInfo>* info) const;
// Get diagnostic information on the specified socket. This is a handy