From 108e9bd4b5628d2ce93862dd88473ed5b1ad36ab Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 12 Mar 2025 17:16:59 +0800 Subject: session(write): fix newline not being printed before write rn if you write() while there is a read("text") it would output the new write() in the same line which is not ideal. --- src/session.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/session.cpp') diff --git a/src/session.cpp b/src/session.cpp index b37d896..463e16a 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -79,11 +79,13 @@ CSession::SRecvData CSession::read() { } onRecv(recvData); + m_isReading = false; return recvData; } CSession::SRecvData CSession::read(const std::string &msg) { write({}, "{}", msg, false); + m_isReading = true; return read(); } @@ -131,6 +133,8 @@ bool CSession::isValid() { template bool CSession::write(eFormatType type, std::format_string fmt, Args &&...args) { std::string msg = NFormatter::fmt(type, fmt, std::forward(args)...); + if (m_isReading) + msg.insert(0, "\n"); if (send(m_sockfd.get(), msg.c_str(), msg.size(), 0) < 0) { onErrno(WRITE); -- cgit v1.2.3