From 56ff86b22ae8d327a5ba4728bde476116d971817 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 21 May 2025 23:59:16 +0800 Subject: session(write): write then restore reading --- src/session.cpp | 10 ++++++---- 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::read() { #ifdef DEBUG onRecv(*recvData); #endif - m_isReading = false; + m_szReading.reset(); return recvData; } @@ -138,7 +138,7 @@ std::unique_ptr 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 fmt, Args &&. return false; std::string msg = NFormatter::fmt(type, fmt, std::forward(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 #include +#include #include #include @@ -62,7 +63,7 @@ class CSession { int m_port; bool m_isAdmin = false; - bool m_isReading = false; + std::optional m_szReading = std::nullopt; bool m_bMuted = false; bool m_bDeaf = true; // init as true as we don't want anything during registerSession -- cgit v1.2.3