From 09d899230c3d31bd405cc3407c6c372ab9091e98 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 4 Mar 2025 23:29:39 +0800 Subject: refactor!: python -> c++ --- src/sessionManager.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/sessionManager.cpp (limited to 'src/sessionManager.cpp') diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp new file mode 100644 index 0000000..a249f61 --- /dev/null +++ b/src/sessionManager.cpp @@ -0,0 +1,29 @@ +#include "sessionManager.hpp" +#include "session.hpp" +#include "server.hpp" +#include + +CSessionManager::CSessionManager() = default; + +CSessionManager::~CSessionManager() { + for (auto &[thread, session] : m_vSessions) { + thread.join(); + } +} + +void CSessionManager::newSession(Hyprutils::OS::CFileDescriptor sockfd) { + std::shared_ptr session = std::make_shared(std::move(sockfd)); + m_vSessions.emplace_back(std::jthread(&CSession::run, session), std::move(session)); +} + +void CSessionManager::enterLoop() { + while (true) { + newSession(Hyprutils::OS::CFileDescriptor{accept(g_pServer->getSocket().take(), nullptr, nullptr) /* awaits new client/session */}); + } +} + +void CSessionManager::broadcast(const std::string &msg) const { + for (const auto &[thread, session] : m_vSessions) { + session->write(msg); + } +} -- cgit v1.2.3