Skip to content

Commit

Permalink
coderabbitai 的修改
Browse files Browse the repository at this point in the history
  • Loading branch information
gukj-spel committed Jul 20, 2024
1 parent 6492156 commit e618652
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/client_map.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#include "client_map.h"
#include "log.h"

namespace pikiwidb {

uint32_t ClientMap::GetAllClientInfos(std::vector<ClientInfo>& results) {
// client info string type: ip, port, fd.
std::shared_lock<std::shared_mutex> client_map_lock(client_map_mutex_);
auto it = clients_.begin();
while (it != clients_.end()) {
auto client = it->second.lock();
if (client) {
for (auto& [id, client_weak] : clients_) {
if (auto client = client_weak.lock()) {
results.emplace_back(client->GetClientInfo());
}
it++;
}
return results.size();
}
Expand All @@ -32,13 +31,15 @@ ClientInfo ClientMap::GetClientsInfoById(int id) {
return client->GetClientInfo();
}
}
ERROR("Client with ID {} not found", id);
return ClientInfo::invalidClientInfo;
}

bool ClientMap::RemoveClientById(int id) {
std::unique_lock client_map_lock(client_map_mutex_);
if (auto it = clients_.find(id); it != clients_.end()) {
clients_.erase(it);
INFO("Removed client with ID {}", id);
return true;
}
return false;
Expand Down Expand Up @@ -81,7 +82,9 @@ bool ClientMap::KillClientById(int client_id) {
auto client = it->second.lock();
if (client) {
client_map_lock.unlock();
INFO("Closing client with ID {}", client_id);
client->Close();
INFO("Client with ID {} closed", client_id);
return true;
}
}
Expand Down

0 comments on commit e618652

Please sign in to comment.