PrevUpHomeNext

c++ Botan::TLS::Stream Constructors


> Start
> constructor 01: master constructor
> constructor 02: Propagate to 01
> constructor 03: Propagate to 01
> constructor 04: Propagate to 02
> Conclusion
> Back: Home

This article talks about c++ Botan::TLS::Stream Constructors (overload).

constructor 01: master constructor

template <typename... Args>
explicit Stream(
	std::shared_ptr<Context> context,
	std::shared_ptr<StreamCallbacks> callbacks,
	Args && ... args
);
template <class StreamLayer, class ChannelT = Channel>
class Stream
{
	...
	...
	StreamLayer m_nextLayer;
};

c++ Example:

auto tls_context = std::make_shared<Botan::TLS::Context>(
	cred, rng, ses, policy, server_info);
auto callbacks = std::make_shared<Botan::TLS::StreamCallbacks>();
boost::asio::thread_pool thread_pool;

Boan::TLS::Stream<boost::beast::tcp_stream> tls_stream{
	tls_context,
	callbacks,
	thread_pool.get_executor()
};
[Note] Note

Distinguish class template and constructor template.

constructor 02: Propagate to constructor 01

template <typename... Args>
explicit Stream(std::shared_ptr<Context> context, Args&&... args);

Propagate from constructor 02 to constructor 01:

constructor 03: Propagate to constructor 01

template <typename Arg>
explicit Stream(
	Arg&& arg,
	std::shared_ptr<Context> context,
	std::shared_ptr<StreamCallbacks> callbacks = std::make_shared<StreamCallbacks>()
);

Propagate from constructor 03 to constructor 01:

Please note that
arg is single arg;
args ... are many args
.

This constructor is for compatibility, not suggested.

Example:

// Work, but not suggested:
Botan::TLS::Stream tls_stream1{io_context, tls_context};

// Work, highly suggested:
Botan::TLS::Stream tls_stream2{tls_context, io_context};

constructor 04: Propagate to constructor 02

template <typename... Args>
explicit Stream(
	Server_Information server_info,
	Args&&... args
):
	Stream{
		std::make_shared<Context>(std::move(server_info)),
		std::forward<Args>(args)...
	}
	{}

By this constructor, it will construct a simple Botan::TLS::Context shared pointer object with server_info parameter only.

I think the constructed tls-context by this constructor does not work in many realistic Internet environment.
To make a fully working tls-context and tls-stream, do not use this constructor.

Conclusion

Constructor 01 and constructor 02 are reommended,
constructor 03 and constructor 04 are not reommended.

//////////////////////////////////////////////////////////////////////

Home

//////////////////////////////////////////////////////////////////////

Sun Jun 28 11:01:14 AM UTC 2026

//////////////////////////////////////////////////////////////////////

Helpful

Spaceship 50 Years Alienated

Role

+

Github:
https://github.com/cppfx/cpphtgt

+

Powered by:
B2 Build | boost quickbook

+

Donate

+

@cppfx.xyz


















PrevUpHomeNext