aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/daemon_handler.cpp
diff options
context:
space:
mode:
authorLee Clagett <code@leeclagett.com>2019-11-17 06:06:10 +0000
committerLee Clagett <code@leeclagett.com>2020-04-03 01:56:17 +0000
commitda9915746219482c25b96406d475c6fde9b02a31 (patch)
tree5b1c6be33c9511dc6af48b63d5f87877b9bd06ae /src/rpc/daemon_handler.cpp
parentMerge pull request #6470 (diff)
downloadmonero-da9915746219482c25b96406d475c6fde9b02a31.tar.xz
Use byte_slice for sending zmq messages - removes data copy within zmq
Diffstat (limited to 'src/rpc/daemon_handler.cpp')
-rw-r--r--src/rpc/daemon_handler.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index d05854e34..de0510fec 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -33,6 +33,7 @@
#include <stdexcept>
#include <boost/uuid/nil_generator.hpp>
+#include <boost/utility/string_ref.hpp>
// likely included by daemon_handler.h's includes,
// but including here for clarity
#include "cryptonote_core/cryptonote_core.h"
@@ -48,7 +49,7 @@ namespace rpc
{
namespace
{
- using handler_function = std::string(DaemonHandler& handler, const rapidjson::Value& id, const rapidjson::Value& msg);
+ using handler_function = epee::byte_slice(DaemonHandler& handler, const rapidjson::Value& id, const rapidjson::Value& msg);
struct handler_map
{
const char* method_name;
@@ -66,7 +67,7 @@ namespace rpc
}
template<typename Message>
- std::string handle_message(DaemonHandler& handler, const rapidjson::Value& id, const rapidjson::Value& parameters)
+ epee::byte_slice handle_message(DaemonHandler& handler, const rapidjson::Value& id, const rapidjson::Value& parameters)
{
typename Message::Request request{};
request.fromJson(parameters);
@@ -903,7 +904,7 @@ namespace rpc
return true;
}
- std::string DaemonHandler::handle(const std::string& request)
+ epee::byte_slice DaemonHandler::handle(const std::string& request)
{
MDEBUG("Handling RPC request: " << request);
@@ -916,8 +917,11 @@ namespace rpc
if (matched_handler == std::end(handlers) || matched_handler->method_name != request_type)
return BAD_REQUEST(request_type, req_full.getID());
- std::string response = matched_handler->call(*this, req_full.getID(), req_full.getMessage());
- MDEBUG("Returning RPC response: " << response);
+ epee::byte_slice response = matched_handler->call(*this, req_full.getID(), req_full.getMessage());
+
+ const boost::string_ref response_view{reinterpret_cast<const char*>(response.data()), response.size()};
+ MDEBUG("Returning RPC response: " << response_view);
+
return response;
}
catch (const std::exception& e)