#include "network/tcp_server.h" // Use the refactored header location #include "spdlog/spdlog.h" #include #include #include // Global io_context for the ASIO services // We make it a pointer to control its lifetime explicitly if needed, // but for this simple main, a global object is fine. boost::asio::io_context g_io_context; /** * @brief Handles termination signals (SIGINT, SIGTERM). * * This function gracefully stops the Boost.Asio io_context, which in turn * will cause the io_context.run() call in main() to unblock and allow * the program to exit cleanly. * * @param signum The signal number received. */ void signalHandler(int signum) { spdlog::warn("Interrupt signal ({}) received. Shutting down.", signum); // Post a stop event to the io_context. This is a thread-safe way // to tell the io_context to stop its event loop. g_io_context.stop(); } int main(int argc, char* argv[]) { try { spdlog::set_level(spdlog::level::debug); spdlog::info("Edge Proxy starting up..."); } catch (const spdlog::spdlog_ex& ex) { std::cerr << "Log initialization failed: " << ex.what() << std::endl; return 1; } signal(SIGINT, signalHandler); signal(SIGTERM, signalHandler); try { constexpr uint16_t port = 8888; TCPServer server(g_io_context, port); spdlog::info("Server is running. Press Ctrl+C to exit."); g_io_context.run(); } catch (const std::exception& e) { spdlog::critical("An unhandled exception occurred: {}", e.what()); return 1; } // --- 4. Shutdown --- spdlog::info("Server has been shut down gracefully. Exiting."); return 0; }