From 38faa173c587606c9cfb0e3fa8fbc77c80617b9e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 13 Dec 2019 09:12:17 +0300 Subject: don't let the write buffer corrupt --- server/main/session.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'server/main/session.cpp') diff --git a/server/main/session.cpp b/server/main/session.cpp index 0ee7f75..7249f0e 100644 --- a/server/main/session.cpp +++ b/server/main/session.cpp @@ -87,15 +87,14 @@ std::string Session::consume_input(std::size_t bytes) { return input; } -void Session::write(std::string output) { +void Session::write(const std::string& output) { const auto self = shared_from_this(); + std::ostream os(&m_buffer); // Include CR (so that Windows' telnet client works) - output += "\r\n"; + os << output << "\r\n"; - boost::asio::const_buffer buffer{output.c_str(), output.length()}; - - boost::asio::async_write(m_socket, std::move(buffer), boost::asio::bind_executor(m_strand, + boost::asio::async_write(m_socket, m_buffer, boost::asio::bind_executor(m_strand, [this, self] (const boost::system::error_code& ec, std::size_t bytes) { handle_write(ec, bytes); })); -- cgit v1.2.3