icinga2/lib/base/netstring.hpp
Julian Brost 41433551bc AsioTlsStream: inherit from SharedObject
All usages of `AsioTlsStream` were already using `Shared<AsioTlsStream>` to
keep a reference-counted instance. This commit moves the reference counting to
`AsioTlsStream` itself by inheriting from `SharedObject`. This will allow to
implement methods making use of the fact that these objects are
reference-counted.

The changes outside of `lib/base/tlsstream.hpp` are merely replacing
`Shared<AsioTlsStream>::Ptr` with `AsioTlsStream::Ptr` everywhere.
2024-11-19 18:07:34 +01:00

44 lines
1.3 KiB
C++

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#ifndef NETSTRING_H
#define NETSTRING_H
#include "base/i2-base.hpp"
#include "base/stream.hpp"
#include "base/tlsstream.hpp"
#include <memory>
#include <boost/asio/spawn.hpp>
namespace icinga
{
class String;
/**
* Helper functions for reading/writing messages in the netstring format.
*
* @see https://cr.yp.to/proto/netstrings.txt
*
* @ingroup base
*/
class NetString
{
public:
static StreamReadStatus ReadStringFromStream(const Stream::Ptr& stream, String *message, StreamReadContext& context,
bool may_wait = false, ssize_t maxMessageLength = -1);
static String ReadStringFromStream(const AsioTlsStream::Ptr& stream, ssize_t maxMessageLength = -1);
static String ReadStringFromStream(const AsioTlsStream::Ptr& stream,
boost::asio::yield_context yc, ssize_t maxMessageLength = -1);
static size_t WriteStringToStream(const Stream::Ptr& stream, const String& message);
static size_t WriteStringToStream(const AsioTlsStream::Ptr& stream, const String& message);
static size_t WriteStringToStream(const AsioTlsStream::Ptr& stream, const String& message, boost::asio::yield_context yc);
static void WriteStringToStream(std::ostream& stream, const String& message);
private:
NetString();
};
}
#endif /* NETSTRING_H */