diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-04 23:29:39 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-04 23:29:39 +0800 |
| commit | 09d899230c3d31bd405cc3407c6c372ab9091e98 (patch) | |
| tree | c6a34436ec3d1a3e99dde3b97dea820d85dc37b9 /src/sessionManager.cpp | |
| parent | bf95e496e2f03fcffb9c6043307f13c99a18d8d0 (diff) | |
refactor!: python -> c++
Diffstat (limited to 'src/sessionManager.cpp')
| -rw-r--r-- | src/sessionManager.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 <print> + +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<CSession>(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); + } +} |
