From 9b61c218b665f94f5cc383a5e607b951ce6af121 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 22 Jun 2025 15:09:42 +0800 Subject: refactor(server): properly use weak pointer API!(server/client:create): require manually specifying server API!(server/client:newClient): now returns a SP instead of WP --- include/libsock/server/clients.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include/libsock/server/clients.hpp') diff --git a/include/libsock/server/clients.hpp b/include/libsock/server/clients.hpp index d8c1921..b18c043 100644 --- a/include/libsock/server/clients.hpp +++ b/include/libsock/server/clients.hpp @@ -21,10 +21,10 @@ struct SData { class Clients : public std::enable_shared_from_this { public: - static SP create(); + static SP create(WP server); ~Clients(); - WP newClient(std::function &)> loopFunc = [](const WP &) { ; }, SP server = pServer); + SP newClient(std::function &)> loopFunc = [](const WP &) { ; }); void broadcast(const std::string &msg, std::optional> self = std::nullopt); // second param only specified when we // want to exclude the sender @@ -44,10 +44,13 @@ class Clients : public std::enable_shared_from_this { std::vector>> m_vClients; std::vector m_vDatas; - SP get(); + WP get(); + + WP m_self; + WP m_wpServer; friend class Client; }; -inline SP pClients; +inline std::vector> vpClients; } // namespace Server } // namespace LibSock -- cgit v1.2.3