]> granicus.if.org Git - icinga2/commitdiff
JsonRpc::ReadMessage(): add Boost ASIO overload
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 19 Feb 2019 10:29:45 +0000 (11:29 +0100)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Mon, 1 Apr 2019 09:40:14 +0000 (11:40 +0200)
lib/remote/jsonrpc.cpp
lib/remote/jsonrpc.hpp

index b07d0e6ed1250533539901c9d2e3f16990d918c5..5f4b6ae9180bf2f1eb4e70bb8d68c04ee9823b8c 100644 (file)
@@ -9,6 +9,7 @@
 #include "base/tlsstream.hpp"
 #include <iostream>
 #include <memory>
+#include <utility>
 #include <boost/asio/spawn.hpp>
 
 using namespace icinga;
@@ -95,6 +96,18 @@ StreamReadStatus JsonRpc::ReadMessage(const Stream::Ptr& stream, String *message
        return StatusNewItem;
 }
 
+String JsonRpc::ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, boost::asio::yield_context yc, ssize_t maxMessageLength)
+{
+       String jsonString = NetString::ReadStringFromStream(stream, yc, maxMessageLength);
+
+#ifdef I2_DEBUG
+       if (GetDebugJsonRpcCached())
+               std::cerr << ConsoleColorTag(Console_ForegroundBlue) << "<< " << jsonString << ConsoleColorTag(Console_Normal) << "\n";
+#endif /* I2_DEBUG */
+
+       return std::move(jsonString);
+}
+
 Dictionary::Ptr JsonRpc::DecodeMessage(const String& message)
 {
        Value value = JsonDecode(message);
index 2efe8022b0cc1f7d47f79cd5fe4608412cfe35f2..137d42a3b7b8326c84a64ddc144bf30d04e10681 100644 (file)
@@ -24,6 +24,7 @@ public:
        static size_t SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message);
        static size_t SendMessage(const std::shared_ptr<AsioTlsStream>& stream, const Dictionary::Ptr& message, boost::asio::yield_context yc);
        static StreamReadStatus ReadMessage(const Stream::Ptr& stream, String *message, StreamReadContext& src, bool may_wait = false, ssize_t maxMessageLength = -1);
+       static String ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, boost::asio::yield_context yc, ssize_t maxMessageLength = -1);
        static Dictionary::Ptr DecodeMessage(const String& message);
 
 private: