diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-09 13:29:24 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:44:57 +0800 |
| commit | 458d92bd4f7bcc61a3ccb1467d5767bd8daceff2 (patch) | |
| tree | e8ac2df7d1ef254ffb6cb5001fc42fc36adb129e /src/session.cpp | |
| parent | 880b6a9275030515e11fdfeb3b6fc074bca9322d (diff) | |
style: remove random const, reorganize stuff
Diffstat (limited to 'src/session.cpp')
| -rw-r--r-- | src/session.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/session.cpp b/src/session.cpp index 7ce2238..06f129e 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -18,15 +18,15 @@ CSession::~CSession() { m_sockfd.reset(); } -void CSession::onConnect() const { +void CSession::onConnect() { log(LOG, "Client connected"); } -void CSession::onDisconnect() const { +void CSession::onDisconnect() { log(LOG, "Client disconnected"); } -void CSession::onErrno(eEventType eventType) const { +void CSession::onErrno(eEventType eventType) { const auto err = strerror(errno); switch (eventType) { case READ: @@ -36,17 +36,18 @@ void CSession::onErrno(eEventType eventType) const { } } -void CSession::onRecv(const SRecvData &data) const { +void CSession::onRecv(const SRecvData &data) { log(LOG, "Received: {}", data.data, data.dataSize); } -void CSession::onSend(const std::string &msg) const { +void CSession::onSend(const std::string &msg) { log(LOG, "Sent: {}", msg); } void CSession::recvManager() { while (true) { SRecvData recvData = read(); + g_pSessionManager->broadcast(recvData.data, eFormatType::CHAT); if (!recvData.good) break; } @@ -98,7 +99,7 @@ bool CSession::registerSession() { return true; } -bool CSession::isValid() const { +bool CSession::isValid() { if (!m_sockfd.isValid() || m_name.empty()) return false; @@ -109,7 +110,7 @@ bool CSession::isValid() const { } template <typename... Args> -bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) const { +bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) { std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...); if (send(m_sockfd.get(), msg.c_str(), msg.size(), 0) < 0) { @@ -120,11 +121,11 @@ bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&. return true; } -bool CSession::write(const std::string &msg, eFormatType type) const { +bool CSession::write(const std::string &msg, eFormatType type) { return write(type, "{}", msg); } -std::string CSession::getName() const { +std::string CSession::getName() { return m_name; } |
