mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 16:14:09 +02:00
Add non-async overloads for JsonRpc::ReadMessage() and JsonRpc::SendMessage()
This commit is contained in:
parent
f4a78380e9
commit
6e7932f157
@ -59,6 +59,25 @@ size_t JsonRpc::SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& me
|
|||||||
return NetString::WriteStringToStream(stream, json);
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to the connected peer and returns the bytes sent.
|
* Sends a message to the connected peer and returns the bytes sent.
|
||||||
*
|
*
|
||||||
@ -106,6 +125,18 @@ StreamReadStatus JsonRpc::ReadMessage(const Stream::Ptr& stream, String *message
|
|||||||
return StatusNewItem;
|
return StatusNewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String JsonRpc::ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, ssize_t maxMessageLength)
|
||||||
|
{
|
||||||
|
String jsonString = NetString::ReadStringFromStream(stream, maxMessageLength);
|
||||||
|
|
||||||
|
#ifdef I2_DEBUG
|
||||||
|
if (GetDebugJsonRpcCached())
|
||||||
|
std::cerr << ConsoleColorTag(Console_ForegroundBlue) << "<< " << jsonString << ConsoleColorTag(Console_Normal) << "\n";
|
||||||
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
|
return std::move(jsonString);
|
||||||
|
}
|
||||||
|
|
||||||
String JsonRpc::ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, boost::asio::yield_context yc, ssize_t maxMessageLength)
|
String JsonRpc::ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, boost::asio::yield_context yc, ssize_t maxMessageLength)
|
||||||
{
|
{
|
||||||
String jsonString = NetString::ReadStringFromStream(stream, yc, maxMessageLength);
|
String jsonString = NetString::ReadStringFromStream(stream, yc, maxMessageLength);
|
||||||
|
@ -22,9 +22,11 @@ class JsonRpc
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static size_t SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message);
|
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);
|
||||||
static size_t SendMessage(const std::shared_ptr<AsioTlsStream>& stream, const Dictionary::Ptr& message, boost::asio::yield_context yc);
|
static size_t SendMessage(const std::shared_ptr<AsioTlsStream>& stream, const Dictionary::Ptr& message, boost::asio::yield_context yc);
|
||||||
static size_t SendRawMessage(const std::shared_ptr<AsioTlsStream>& stream, const String& json, boost::asio::yield_context yc);
|
static size_t SendRawMessage(const std::shared_ptr<AsioTlsStream>& stream, const String& json, 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 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, ssize_t maxMessageLength = -1);
|
||||||
static String ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, boost::asio::yield_context yc, 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);
|
static Dictionary::Ptr DecodeMessage(const String& message);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user