mirror of https://github.com/Icinga/icinga2.git
NetString::WriteStringToStream(): add Boost ASIO overload
This commit is contained in:
parent
832365195d
commit
43658de529
|
@ -2,7 +2,12 @@
|
|||
|
||||
#include "base/netstring.hpp"
|
||||
#include "base/debug.hpp"
|
||||
#include "base/tlsstream.hpp"
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
|
@ -110,6 +115,29 @@ size_t NetString::WriteStringToStream(const Stream::Ptr& stream, const String& s
|
|||
return msg.GetLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data into a stream using the netstring format and returns bytes written.
|
||||
*
|
||||
* @param stream The stream.
|
||||
* @param str The String that is to be written.
|
||||
*
|
||||
* @return The amount of bytes written.
|
||||
*/
|
||||
size_t NetString::WriteStringToStream(const std::shared_ptr<AsioTlsStream>& stream, const String& str, boost::asio::yield_context yc)
|
||||
{
|
||||
namespace asio = boost::asio;
|
||||
|
||||
std::ostringstream msgbuf;
|
||||
WriteStringToStream(msgbuf, str);
|
||||
|
||||
String msg = msgbuf.str();
|
||||
asio::const_buffer msgBuf (msg.CStr(), msg.GetLength());
|
||||
|
||||
asio::async_write(*stream, msgBuf, yc);
|
||||
|
||||
return msg.GetLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data into a stream using the netstring format.
|
||||
*
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include "base/i2-base.hpp"
|
||||
#include "base/stream.hpp"
|
||||
#include "base/tlsstream.hpp"
|
||||
#include <memory>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -24,6 +27,7 @@ public:
|
|||
static StreamReadStatus ReadStringFromStream(const Stream::Ptr& stream, String *message, StreamReadContext& context,
|
||||
bool may_wait = false, ssize_t maxMessageLength = -1);
|
||||
static size_t WriteStringToStream(const Stream::Ptr& stream, const String& message);
|
||||
static size_t WriteStringToStream(const std::shared_ptr<AsioTlsStream>& stream, const String& message, boost::asio::yield_context yc);
|
||||
static void WriteStringToStream(std::ostream& stream, const String& message);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue