summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libsock/server/clients.hpp2
-rw-r--r--src/server/clients.cpp6
2 files changed, 3 insertions, 5 deletions
diff --git a/include/libsock/server/clients.hpp b/include/libsock/server/clients.hpp
index a80fb4a..9e08797 100644
--- a/include/libsock/server/clients.hpp
+++ b/include/libsock/server/clients.hpp
@@ -25,7 +25,7 @@ class Clients : public std::enable_shared_from_this<Clients> {
static SP<Clients> create();
~Clients();
- WP<Client> newClient(SP<Server> server = pServer, std::optional<std::function<std::any(WP<Client>)>> cb = std::nullopt);
+ WP<Client> newClient(std::function<std::any(const WP<Client> &)> loopFunc = [](const WP<Client> &) { return std::any(); }, SP<Server> server = pServer);
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 6f3f4e4..2bf82b4 100644
--- a/src/server/clients.cpp
+++ b/src/server/clients.cpp
@@ -58,12 +58,10 @@ Clients::~Clients() {
}
}
-WP<Client> Clients::newClient(SP<Server> server, std::optional<std::function<std::any(WP<Client>)>> cb) {
+WP<Client> Clients::newClient(std::function<std::any(const WP<Client> &)> loopFunc, SP<Server> server) {
SP client = SP<Client>(new Client(server, shared_from_this()));
- auto &instance = m_vClients.emplace_back(std::jthread([&client]() { client->runLoop(); }), client);
+ auto &instance = m_vClients.emplace_back(std::jthread([&client, &loopFunc]() { loopFunc(client); }), client);
instance.second->self = std::weak_ptr<Client>(instance.second);
- if (cb)
- (*cb)(instance.second);
return instance.second;
}