diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-13 19:43:56 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:45:00 +0800 |
| commit | b000ae9e41b8699d1c7d6eefa0441ee05c970d25 (patch) | |
| tree | d8b3a2fb13c39911f992890d177abb00e1069ce9 /src/session.cpp | |
| parent | 95fe8f6c660a1c3bf91b5ab78f95ef0c35d8990c (diff) | |
fix: NONEWLINE more explicit
fixes a problem where all of socket wrote response is using NONE
fmt(944b18bde52778b32c31dc23f3d90fc17b94794f)
so all of them don't have \n
Diffstat (limited to 'src/session.cpp')
| -rw-r--r-- | src/session.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/session.cpp b/src/session.cpp index 6744fc9..228f183 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -58,7 +58,7 @@ void CSession::onSend(const std::string &msg) { void CSession::recvLoop() { while (true) { - auto recvData = read(NFormatter::fmt(NONE, "{}: ", m_name)); + auto recvData = read(NFormatter::fmt(NONEWLINE, "{}: ", m_name)); if (!recvData->good) break; @@ -90,7 +90,7 @@ std::unique_ptr<CSession::SRecvData> CSession::read() { } std::unique_ptr<CSession::SRecvData> CSession::read(const std::string &msg) { - write("{}", msg, false); + write(NONEWLINE, "{}", msg, false); m_isReading = true; return read(); } @@ -159,6 +159,20 @@ bool CSession::write(std::format_string<Args...> fmt, Args &&...args) { return true; } +template <typename... Args> +bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) { + std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...); + if (m_isReading) + msg.insert(0, "\n"); + + if (send(m_sockfd.get(), msg.c_str(), msg.size(), 0) < 0) { + onErrno(WRITE); + return false; + } + onSend(msg); + return true; +} + bool CSession::write(const std::string &msg) { return write("{}", msg); } |
