aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-12-13 09:12:17 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-12-13 09:12:17 +0300
commit38faa173c587606c9cfb0e3fa8fbc77c80617b9e (patch)
tree97ca22e6cc6381df2de4d2bc8937de29f6eaa17f
parentstress_test.py: fix for 3.6 (diff)
downloadmath-server-38faa173c587606c9cfb0e3fa8fbc77c80617b9e.tar.gz
math-server-38faa173c587606c9cfb0e3fa8fbc77c80617b9e.zip
don't let the write buffer corrupt
-rw-r--r--server/main/session.cpp9
-rw-r--r--server/main/session.hpp2
2 files changed, 5 insertions, 6 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);
}));
diff --git a/server/main/session.hpp b/server/main/session.hpp
index ace3755..98f28dd 100644
--- a/server/main/session.hpp
+++ b/server/main/session.hpp
@@ -25,7 +25,7 @@ private:
void close();
void read();
- void write(std::string);
+ void write(const std::string&);
void handle_read(const boost::system::error_code&, std::size_t);
void handle_write(const boost::system::error_code&, std::size_t);