From b46ba43e06aba714abc0afb29566a56d69891691 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 16 Jun 2025 19:25:57 +0800 Subject: fix!: create new client without SP(this) param API: removed run(), use newClient() to accept a new client, now returning a WP of the client instance API: allow all cb to return std::any --- src/server/clients.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/server/clients.cpp') diff --git a/src/server/clients.cpp b/src/server/clients.cpp index 5fc63df..210581a 100644 --- a/src/server/clients.cpp +++ b/src/server/clients.cpp @@ -1,5 +1,6 @@ #include "libsock/server/client.hpp" #include +#include #include #include #include @@ -44,17 +45,13 @@ Clients::~Clients() { } } -void Clients::newClient(std::optional> cb) { - if (cb) - (*cb)(); - SP client = std::make_shared(pServer, SP(this)); +WP Clients::newClient(std::optional)>> cb) { + SP client = std::make_shared(); auto &instance = m_vClients.emplace_back(std::jthread([client]() { client->run(); }), client); instance.second->self = std::weak_ptr(instance.second); -} - -void Clients::run(std::optional> cb) { - while (true) - newClient(cb); + if (cb) + (*cb)(instance.second); + return instance.second; } void Clients::broadcast(const std::string &msg, std::optional> self) { -- cgit v1.2.3