From cad2569f10e6c0131e5e645ee76330c776b91547 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 19 Jun 2025 18:45:34 +0800 Subject: fix!: share pointer for details: https://stackoverflow.com/a/5548314 --- include/libsock/server/clients.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'include/libsock/server/clients.hpp') diff --git a/include/libsock/server/clients.hpp b/include/libsock/server/clients.hpp index ba0b40d..8eccbb7 100644 --- a/include/libsock/server/clients.hpp +++ b/include/libsock/server/clients.hpp @@ -3,6 +3,7 @@ #include "../types.hpp" #include #include +#include #include #include #include @@ -17,9 +18,10 @@ struct SData { std::string msg; std::optional> sender = std::nullopt; }; -class Clients { + +class Clients : public std::enable_shared_from_this { public: - Clients(); + static SP create(); ~Clients(); WP newClient(std::optional)>> cb = std::nullopt); @@ -36,13 +38,16 @@ class Clients { std::vector getDatas() const; private: + Clients(); void broadcast(const SData &msg); std::vector>> m_vClients; std::vector m_vDatas; + SP get(); + friend class Client; }; - +inline SP pClients; } // namespace Server } // namespace LibSock -- cgit v1.2.3