Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
marsevilspirit committed Jan 16, 2025
1 parent f0e0fe1 commit 886a3d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/net/event_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ int EventServer<T>::StartThreadManager(bool serverMode) {
listen->SetListenAddr(listenAddr);
listenSockets.push_back(listen);
if (auto ret = listen->Init() != static_cast<int>(NetListen::OK)) {
listenSockets.clear(); // Clean up all sockets
return ret;
}
}
Expand All @@ -267,6 +268,7 @@ int EventServer<T>::StartThreadManager(bool serverMode) {
listen.reset(ListenSocket::CreateTCPListen());
listen->SetListenAddr(listenAddr);
if (auto ret = listen->Init() != static_cast<int>(NetListen::OK)) {
listenSockets.clear(); // Clean up all sockets
return ret;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/net/socket_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ struct SocketAddr {
addr_.addr4_.sin_port = htons(hostPort);
return;
}
::inet_pton(AF_INET6, ip.c_str(), &addr_.addr6_.sin6_addr);
if (::inet_pton(AF_INET6, ip.c_str(), &addr_.addr6_.sin6_addr) != 1) {
throw std::invalid_argument("Invalid IP address format");
}
addr_.addr6_.sin6_family = AF_INET6;
addr_.addr6_.sin6_port = htons(hostPort);
}
Expand All @@ -70,7 +72,9 @@ struct SocketAddr {
}
}
char ipv6_buf[INET6_ADDRSTRLEN] = {0};
::inet_ntop(AF_INET6, &addr_.addr6_.sin6_addr, ipv6_buf, sizeof(ipv6_buf));
if (!::inet_ntop(AF_INET6, &addr_.addr6_.sin6_addr, ipv6_buf, sizeof(ipv6_buf))) {
throw std::runtime_error("Failed to convert IPv6 address to string");
}
return ipv6_buf;
}

Expand Down
3 changes: 2 additions & 1 deletion src/raft/raft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ butil::Status Raft::Init(std::string& group_id, bool initial_conf_is_null) {
assert(group_id.size() == RAFT_GROUPID_LEN);
this->group_id_ = group_id;

// FIXME: g_config.ip is default to 127.0.0.1, which may not work in cluster.
// NOTE: Default raft_ip is 127.0.0.1. For cluster setup, configure the appropriate
// IP address in kiwi.conf using the 'raft-ip' directive.
raw_addr_ = g_config.raft_ip + ":" + std::to_string(port);
butil::ip_t ip;
auto ret = butil::str2ip(g_config.raft_ip.c_str(), &ip);
Expand Down

0 comments on commit 886a3d4

Please sign in to comment.