Boost logo

Boost :

From: Seth (bugs_at_[hidden])
Date: 2024-10-21 22:49:30


On Mon, Oct 21, 2024, at 4:32 PM, Ivica Siladic wrote:
> Hi Seth,
>
> However, since the stream type cannot be type-erased, this callback would need to be a template function.

How so? The signature might have to depend on template arguments. That's not necessarily as intrusive

> During the stream creation, the user would also need access to the corresponding SSL context, which
> could lead to the use of a global variable or a Meyers-like
> singleton—neither of which is ideal.

This was the whole point of mentioning factories: the factories can *own* their own ssl context (or whatever else is required). It's effectively an example of Inversion Of Control.

Yes some people will cut corners and use bad practices. You could make sure the examples don't.

>
> Another option is to use a template class, such as TlsStreamFactory,
> and then templatize the mqtt_client class with this factory. This
> approach would allow the creation of a well-defined concept (i.e.,
> prescribing the required interface).

I guess so. I would probably expect a more generalized concept (StreamFactory) to create any AsyncStream, but I have no idea whether such a thing makes sense in the context of your library.

> Honestly, I’m not sure which approach is better.

Me neither. Those are hard choices. I mostly intended to provide inspiration.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk