X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/a6823135a2eb8a485b40288807fb95e66e48b727..32d9767958eece65c3d6feb02419a3f003dc2f0a:/projects/stargazer/plugins/other/radius/radius.cpp?ds=inline diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index e517c959..8e5b37a8 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,11 +1,7 @@ #include "radius.h" -#include "server.h" #include "radproto/error.h" - #include "stg/common.h" -#include -#include #include #include @@ -67,27 +63,6 @@ RADIUS::RADIUS() { } -int RADIUS::Run(std::stop_token token) -{ - SetRunning(true); - - try - { - boost::asio::io_service ioService; - Server server(ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries()); - ioService.run(); - } - catch (const std::exception& e) - { - m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what()); - m_logger("Exception in RADIUS:: Run(): %s", e.what()); - printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what()); - } - - SetRunning(false); - return 0; -} - int RADIUS::ParseSettings() { auto ret = m_radSettings.ParseSettings(m_settings); @@ -115,6 +90,9 @@ int RADIUS::Stop() m_thread.request_stop(); + if (m_server) + m_server->stop(); + m_thread.join(); return 0; } @@ -130,3 +108,24 @@ void RADIUS::SetRunning(bool val) const std::lock_guard lock(m_mutex); m_running = val; } + +int RADIUS::Run(std::stop_token token) +{ + SetRunning(true); + + try + { + if (!m_server) + m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger); + m_ioService.run(); + } + catch (const std::exception& e) + { + m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what()); + m_logger("Exception in RADIUS:: Run(): %s", e.what()); + printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what()); + } + + SetRunning(false); + return 0; +}