Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Changing server settings #103

Open Lord-Kamina opened 4 years ago

Lord-Kamina commented 4 years ago

Say I have an instance of http_server_t, and most of the server settings are end-user configurable. Is it possible to change said server's settings (Of course I assume I'd need to close the server and open it again), or is it better to just make a new instance with the new settings to replace the old one?

Additionally, in a situation such as described above... what should I do with the io_context? I'm currently using restinio::own_io_context(), do I also need to stop and restart the io_context (I'm thinking yes), would you recommend I keep using restinio::own_io_context() or should I switch to an external io_context?

eao197 commented 4 years ago

Is it possible to change said server's settings (Of course I assume I'd need to close the server and open it again), or is it better to just make a new instance with the new settings to replace the old one?

In the current design, the settings are split to several parts and those parts are stored in different objects behind http_server_t instance. And this is performed only at the initialization time (in the constructors of http_server_t and related objects). So you can't change server settings after the creation of http_server_t instance in RESTinio 0.6. You have to recreate the server to apply new settings.

I'm currently using restinio::own_io_context(), do I also need to stop and restart the io_context (I'm thinking yes),

If you recreate http_server_t instance with own_io_contect then io_context will be recreated automatically too. If it is an issue for your usecase (for example, you attach some of your objects to RESTinio's io_context and don't want to lost them) then you have to use external io_context to keep.