From 8e7f5fd041f7eb5730d0810d19a5d96183e41a36 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 10 Apr 2015 16:51:40 +0200 Subject: Correct usage of json parser buffers --- src/ManagementServer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ManagementServer.cpp b/src/ManagementServer.cpp index fe1a0be..fc0a43e 100644 --- a/src/ManagementServer.cpp +++ b/src/ManagementServer.cpp @@ -298,7 +298,9 @@ void ManagementServer::handle_accept( if (length > 0) { boost::unique_lock lock(m_configmutex); m_pt.clear(); - boost::property_tree::json_parser::read_json(jsonbuffer, m_pt); + + std::istream json_stream(&jsonbuffer); + boost::property_tree::json_parser::read_json(json_stream, m_pt); } else if (length == 0) { etiLog.level(warn) << @@ -319,14 +321,13 @@ void ManagementServer::handle_accept( std::stringstream ss; boost::property_tree::json_parser::write_json(ss, m_pt); - boost::asio::write(*socket, ss, + boost::asio::write(*socket, boost::asio::buffer(ss.str()), boost::asio::transfer_all(), ignored_error); } else { - std::stringstream ss; - ss << "Invalid command\n"; - boost::asio::write(*socket, ss, + std::string invcmd("Invalid command\n"); + boost::asio::write(*socket, boost::asio::buffer(invcmd), boost::asio::transfer_all(), ignored_error); } -- cgit v1.2.3