From 2320470d342db4cb5ae0ae717dfc5ac94bd3f2d2 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 21 Jun 2025 21:18:28 +0800 Subject: internal(server): remove return of std::any for callbacks use bool for cases for premature return --- src/server/clients.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/server/clients.cpp') diff --git a/src/server/clients.cpp b/src/server/clients.cpp index 2bf82b4..e1dd161 100644 --- a/src/server/clients.cpp +++ b/src/server/clients.cpp @@ -1,7 +1,6 @@ #include "libsock/server/clients.hpp" #include "libsock/server/client.hpp" #include -#include #include #include #include @@ -12,12 +11,12 @@ using namespace LibSock::Server; namespace LibSock { namespace Server { -void Clients::shutdownClients(std::optional>> &)>> cb) { +void Clients::shutdownClients(std::optional>> &)>> cb) { if (m_vClients.empty()) return; - if (cb) - (*cb)(m_vClients); + if (cb && !(*cb)(m_vClients)) + return; for (auto &[thread, client] : m_vClients) { if (thread.joinable()) @@ -58,7 +57,7 @@ Clients::~Clients() { } } -WP Clients::newClient(std::function &)> loopFunc, SP server) { +WP Clients::newClient(std::function &)> loopFunc, SP server) { SP client = SP(new Client(server, shared_from_this())); auto &instance = m_vClients.emplace_back(std::jthread([&client, &loopFunc]() { loopFunc(client); }), client); instance.second->self = std::weak_ptr(instance.second); @@ -93,7 +92,7 @@ std::vector Clients::getDatas() const { return m_vDatas; } -void Clients::kick(WP clientWeak, const bool kill, const std::string &reason, std::optional>>::iterator &)>> cb) { +void Clients::kick(WP clientWeak, const bool kill, const std::string &reason, std::optional>>::iterator &)>> cb) { auto client = clientWeak.lock(); if (!client) return; @@ -103,8 +102,8 @@ void Clients::kick(WP clientWeak, const bool kill, const std::string &re if (client) // this only exist when the client is registered // not sure why the second is null - if (cb) - (*cb)(it); + if (cb && !(*cb)(it)) + return; if (!reason.empty()) client->write(reason); -- cgit v1.2.3