diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-05-21 23:59:16 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-05-21 23:59:16 +0800 |
| commit | 56ff86b22ae8d327a5ba4728bde476116d971817 (patch) | |
| tree | 2a2bb87f3970d4303fa27166abaddc66792e050c | |
| parent | 71cb5a2f07dc98a1ad232c639bf76d0efd9c43d5 (diff) | |
session(write): write then restore reading
| -rw-r--r-- | src/session.cpp | 10 | ||||
| -rw-r--r-- | src/session.hpp | 3 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/session.cpp b/src/session.cpp index 6631fae..7010acb 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -127,7 +127,7 @@ std::unique_ptr<CSession::SRecvData> CSession::read() { #ifdef DEBUG onRecv(*recvData); #endif - m_isReading = false; + m_szReading.reset(); return recvData; } @@ -138,7 +138,7 @@ std::unique_ptr<CSession::SRecvData> CSession::read(const std::string &msg, bool write(NONEWLINE, "{}", msg, false); if (bypassDeaf && deaf) setDeaf(true); - m_isReading = true; + m_szReading = msg; return read(); } @@ -224,8 +224,10 @@ bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&. return false; std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...); - if (m_isReading) - msg.insert(0, "\n"); + if (m_szReading) { + msg.insert(0, "\r"); + msg.append(*m_szReading); + } if (send(m_sockfd.get(), msg.c_str(), msg.size(), 0) < 0) { onErrno(WRITE); diff --git a/src/session.hpp b/src/session.hpp index ad2cc24..882c630 100644 --- a/src/session.hpp +++ b/src/session.hpp @@ -5,6 +5,7 @@ #include "format.hpp" #include <memory> #include <netinet/in.h> +#include <optional> #include <string> #include <thread> @@ -62,7 +63,7 @@ class CSession { int m_port; bool m_isAdmin = false; - bool m_isReading = false; + std::optional<std::string> m_szReading = std::nullopt; bool m_bMuted = false; bool m_bDeaf = true; // init as true as we don't want anything during registerSession |
