3 #ifndef GRAIL_TCPSERVER_H
4 #define GRAIL_TCPSERVER_H
8 #include "../libs/poco/Net/include/Poco/Net/SocketAddress.h"
9 #include "../libs/poco/Net/include/Poco/Net/SocketStream.h"
10 #include "../libs/poco/Net/include/Poco/Net/StreamSocket.h"
11 #include "../libs/poco/Net/include/Poco/Net/TCPServer.h"
30 void SendToAll(
const std::string& data);
31 void SendToAll(
const uint8_t* data, std::size_t dataSize, DataType dataType);
33 void AddEventOnConnection(std::function<
void()> event);
35 bool IsAnyConnected()
const;
38 void AcceptConnections();
39 void CheckDisconnects();
41 constexpr
static const Poco::Int32 MAGIC = 0x22669977;
42 const std::string STREAM_MAGIC;
45 std::atomic<bool> isWorking{
false};
47 std::unique_ptr<Poco::Net::ServerSocket> server;
48 std::unique_ptr<std::thread> connectionAcceptorThread =
nullptr;
49 std::unique_ptr<std::thread> disconnectCheckerThread =
nullptr;
50 std::vector<Poco::Net::StreamSocket> clients{};
51 std::vector<std::function<void()>> onClientConnected{};
53 mutable std::mutex clientsMutex{};
54 std::mutex eventMutex{};
55 std::mutex stateChangeMutex{};
60 #endif // GRAIL_TCPSERVER_H