add gracefull shutdown

This commit is contained in:
Bartosz Wieczorek 2025-08-06 20:59:38 +02:00
parent 1948a4a3d2
commit 899659ab70
2 changed files with 7 additions and 7 deletions

View File

@ -21,7 +21,7 @@ std::string make_topic(const Args &... args) {
return "";
}
auto separator = R"(\)"s;
auto separator = R"(/)"s;
std::array< std::string_view, count > segments{std::string_view(args)...};
size_t total_size = length(args...) + segments.size();

View File

@ -13,8 +13,8 @@
#include <ranczo-io/utils/mqtt_client.hpp>
#include <ranczo-io/utils/timer.hpp>
#include <vector>
#include <csignal>
#include <vector>
namespace ranczo {
@ -31,14 +31,14 @@ namespace ranczo {
using namespace std::chrono_literals;
using namespace std::string_view_literals;
std::atomic<bool> running = true;
boost::asio::io_context* g_io = nullptr;
std::atomic< bool > running = true;
boost::asio::io_context * g_io = nullptr;
void signal_handler(int signum) {
spdlog::warn("Signal received: {}, stopping io_context...", signum);
running = false;
if (g_io) {
g_io->stop(); // <--- This stops io_context.run()
if(g_io) {
g_io->stop(); // <--- This stops io_context.run()
}
}
@ -48,7 +48,7 @@ int main() {
boost::asio::io_context io_context;
g_io = &io_context;
// Register signal handler
spdlog::info("Registering signal handlers");
std::signal(SIGINT, signal_handler);