Tectu / malloy

A cross-platform C++20 library providing embeddable server & client components for HTTP and WebSocket.
BSD 3-Clause "New" or "Revised" License
66 stars 8 forks source link

Cannot init both a server and a client #15

Closed 0x00002a closed 3 years ago

0x00002a commented 3 years ago

Currently there is a static guard variable in the root controller init method that means any inits after the first will always fail. This is an issue if one wants to have multiple servers or clients (or client + server). A use case example is having a server which sometimes needs to make requests to other sites and which creates a temp client to do it. I'm guessing its to prevent multiple io_context's? Maybe could add a ctor or init argument that takes in another controller and duplicates the needed state?

Tectu commented 3 years ago

I'm guessing its to prevent multiple io_context's?

Nah, so far this was just out of convenience. The init-guard variable can easily be moved to become a private member instead. Technically, this is not necessary at all and we could just rely on documentation to tell the user not to attempt re-initialization.

As far as I know / can tell it's perfectly fine to have multiple io_contexts around.

Tectu commented 3 years ago

The fact that you can currently not initialize both a server and a client is a side effect. I only very recently introduced the general controller from which the server and client controllers inherit.