diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-21 21:18:28 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-22 11:13:20 +0800 |
| commit | 2320470d342db4cb5ae0ae717dfc5ac94bd3f2d2 (patch) | |
| tree | a20a988ea60284374865405118bf38324b1a368a /include/libsock | |
| parent | 3e11125a1694d61fb0bd578783437acfca8eacc3 (diff) | |
internal(server): remove return of std::any for callbacks
use bool for cases for premature return
Diffstat (limited to 'include/libsock')
| -rw-r--r-- | include/libsock/server/client.hpp | 11 | ||||
| -rw-r--r-- | include/libsock/server/clients.hpp | 7 |
2 files changed, 8 insertions, 10 deletions
diff --git a/include/libsock/server/client.hpp b/include/libsock/server/client.hpp index f7d9889..2549ef5 100644 --- a/include/libsock/server/client.hpp +++ b/include/libsock/server/client.hpp @@ -3,7 +3,6 @@ #include "../types.hpp" #include "clients.hpp" #include "server.hpp" -#include <any> #include <format> #include <functional> #include <netinet/in.h> @@ -37,14 +36,14 @@ class Client { const std::string &getIp() const; bool isAdmin() const; - UP<SRecvData> read(std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); - UP<SRecvData> read(const std::string &msg, std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); - bool write(const std::string &msg, std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); + UP<SRecvData> read(std::optional<std::function<bool(const SRecvData &)>> cb = std::nullopt); + UP<SRecvData> read(const std::string &msg, std::optional<std::function<bool(const SRecvData &)>> cb = std::nullopt); + bool write(const std::string &msg, std::optional<std::function<bool(const SRecvData &)>> cb = std::nullopt); template <typename... Args> bool write(std::format_string<Args...> fmt, Args &&...args); void resumeHistory(); - void runLoop(bool resumeHistory = true, std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); + void runLoop(bool resumeHistory = true, std::optional<std::function<bool(const SRecvData &)>> cb = std::nullopt); bool isValid(); @@ -62,7 +61,7 @@ class Client { std::optional<std::string> m_szReading = std::nullopt; - void recvLoop(std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); + void recvLoop(std::optional<std::function<bool(const SRecvData &)>> cb = std::nullopt); friend class Clients; }; diff --git a/include/libsock/server/clients.hpp b/include/libsock/server/clients.hpp index 9e08797..d8c1921 100644 --- a/include/libsock/server/clients.hpp +++ b/include/libsock/server/clients.hpp @@ -2,7 +2,6 @@ #include "../types.hpp" #include "server.hpp" -#include <any> #include <functional> #include <memory> #include <optional> @@ -25,14 +24,14 @@ class Clients : public std::enable_shared_from_this<Clients> { static SP<Clients> create(); ~Clients(); - WP<Client> newClient(std::function<std::any(const WP<Client> &)> loopFunc = [](const WP<Client> &) { return std::any(); }, SP<Server> server = pServer); + WP<Client> newClient(std::function<void(const WP<Client> &)> loopFunc = [](const WP<Client> &) { ; }, 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 - void kick(WP<Client> client, const bool kill = false, const std::string &reason = "", std::optional<std::function<std::any(const std::vector<std::pair<std::jthread, SP<Client>>>::iterator &)>> cb = std::nullopt); + void kick(WP<Client> client, const bool kill = false, const std::string &reason = "", std::optional<std::function<bool(const std::vector<std::pair<std::jthread, SP<Client>>>::iterator &)>> cb = std::nullopt); void addClient(const Client &client); - void shutdownClients(std::optional<std::function<std::any(const std::vector<std::pair<std::jthread, SP<Client>>> &)>> cb = std::nullopt); + void shutdownClients(std::optional<std::function<bool(const std::vector<std::pair<std::jthread, SP<Client>>> &)>> cb = std::nullopt); SP<Client> getByIp(const std::string &ip) const; std::vector<SP<Client>> getClients() const; |
