diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-19 18:47:32 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-19 18:47:32 +0800 |
| commit | eb78b04ca2f4fc334365f2a26537691aa1c91f48 (patch) | |
| tree | a83dfef5f7d532012d234e182f03dd874a56f892 | |
| parent | cad2569f10e6c0131e5e645ee76330c776b91547 (diff) | |
API(session/clients:newClient): allow custom server ptr
| -rw-r--r-- | include/libsock/server/clients.hpp | 3 | ||||
| -rw-r--r-- | src/server/clients.cpp | 4 |
2 files changed, 4 insertions, 3 deletions
diff --git a/include/libsock/server/clients.hpp b/include/libsock/server/clients.hpp index 8eccbb7..a80fb4a 100644 --- a/include/libsock/server/clients.hpp +++ b/include/libsock/server/clients.hpp @@ -1,6 +1,7 @@ #pragma once #include "../types.hpp" +#include "server.hpp" #include <any> #include <functional> #include <memory> @@ -24,7 +25,7 @@ class Clients : public std::enable_shared_from_this<Clients> { static SP<Clients> create(); ~Clients(); - WP<Client> newClient(std::optional<std::function<std::any(WP<Client>)>> cb = std::nullopt); + WP<Client> newClient(SP<Server> server = pServer, std::optional<std::function<std::any(WP<Client>)>> cb = std::nullopt); void broadcast(const std::string &msg, std::optional<WP<Client>> self = std::nullopt); // second param only specified when we // want to exclude the sender diff --git a/src/server/clients.cpp b/src/server/clients.cpp index 201ccc6..ac3546e 100644 --- a/src/server/clients.cpp +++ b/src/server/clients.cpp @@ -58,8 +58,8 @@ Clients::~Clients() { } } -WP<Client> Clients::newClient(std::optional<std::function<std::any(WP<Client>)>> cb) { - SP client = SP<Client>(new Client(pServer, shared_from_this())); +WP<Client> Clients::newClient(SP<Server> server, std::optional<std::function<std::any(WP<Client>)>> cb) { + SP client = SP<Client>(new Client(server, shared_from_this())); auto &instance = m_vClients.emplace_back(std::jthread([client]() { client->run(); }), client); instance.second->self = std::weak_ptr<Client>(instance.second); if (cb) |
