From 42153431759c5c4d6a751b8efcf1492f69dea3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 20 Nov 2016 11:14:20 +0100 Subject: [PATCH] bugfix: messages would only be received till the first whitespace --- message.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/message.cpp b/message.cpp index a2cf025..d3ab141 100644 --- a/message.cpp +++ b/message.cpp @@ -8,8 +8,7 @@ void message::send(boost::asio::ip::tcp::socket& socket) { system::error_code ec; - asio::write(socket, asio::buffer(get_message_length()), ec); - asio::write(socket, asio::buffer(get_message()), ec); + asio::write(socket, asio::buffer(get_message_length() + get_message()), ec); if (ec) throw std::runtime_error("Networking error: " + ec.message()); @@ -28,8 +27,9 @@ void message::receive(boost::asio::ip::tcp::socket& socket) asio::read(socket, sb, asio::transfer_exactly(len), ec); data.clear(); + data.reserve(len); is.clear(); - is >> data; + data = std::string(std::istreambuf_iterator(is), std::istreambuf_iterator()); if (ec) throw std::runtime_error("Networking error: " + ec.message());