#include "base/console.hpp"
#include "base/scriptglobal.hpp"
#include "base/convert.hpp"
+#include "base/tlsstream.hpp"
#include <iostream>
+#include <memory>
+#include <boost/asio/spawn.hpp>
using namespace icinga;
return NetString::WriteStringToStream(stream, json);
}
+/**
+ * Sends a message to the connected peer and returns the bytes sent.
+ *
+ * @param message The message.
+ *
+ * @return The amount of bytes sent.
+ */
+size_t JsonRpc::SendMessage(const std::shared_ptr<AsioTlsStream>& stream, const Dictionary::Ptr& message, boost::asio::yield_context yc)
+{
+ String json = JsonEncode(message);
+
+#ifdef I2_DEBUG
+ if (GetDebugJsonRpcCached())
+ std::cerr << ConsoleColorTag(Console_ForegroundBlue) << ">> " << json << ConsoleColorTag(Console_Normal) << "\n";
+#endif /* I2_DEBUG */
+
+ return NetString::WriteStringToStream(stream, json, yc);
+}
+
StreamReadStatus JsonRpc::ReadMessage(const Stream::Ptr& stream, String *message, StreamReadContext& src, bool may_wait, ssize_t maxMessageLength)
{
String jsonString;
#include "base/stream.hpp"
#include "base/dictionary.hpp"
+#include "base/tlsstream.hpp"
#include "remote/i2-remote.hpp"
+#include <memory>
+#include <boost/asio/spawn.hpp>
namespace icinga
{
{
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 Dictionary::Ptr DecodeMessage(const String& message);