diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-13 09:12:17 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-13 09:12:17 +0300 |
commit | 38faa173c587606c9cfb0e3fa8fbc77c80617b9e (patch) | |
tree | 97ca22e6cc6381df2de4d2bc8937de29f6eaa17f /server/main/session.cpp | |
parent | stress_test.py: fix for 3.6 (diff) | |
download | math-server-38faa173c587606c9cfb0e3fa8fbc77c80617b9e.tar.gz math-server-38faa173c587606c9cfb0e3fa8fbc77c80617b9e.zip |
don't let the write buffer corrupt
Diffstat (limited to 'server/main/session.cpp')
-rw-r--r-- | server/main/session.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
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); })); |