From 22fe4f0e82ba5506da27f24bfad439d339804878 Mon Sep 17 00:00:00 2001 From: Ayush Mehra Date: Thu, 28 Nov 2024 10:03:21 +0530 Subject: [PATCH 1/2] create sideband manager --- CMakeLists.txt | 1 + source/server/core_server.cpp | 7 ++++--- source/server/sideband_manager.cpp | 14 ++++++++++++++ source/server/sideband_manager.h | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 source/server/sideband_manager.cpp create mode 100644 source/server/sideband_manager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2771c1c52..231913fc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -448,6 +448,7 @@ add_executable(ni_grpc_device_server "source/server/calibration_operations_restricted_service_registrar.cpp" "source/server/calibration_operations_restricted_service.cpp" "source/server/core_server.cpp" + "source/server/sideband_manager.cpp" "source/server/core_services_registrar.cpp" "source/server/data_moniker_service.cpp" "source/server/debug_session_properties_restricted_service_registrar.cpp" diff --git a/source/server/core_server.cpp b/source/server/core_server.cpp index 9521e6810..469f30d30 100644 --- a/source/server/core_server.cpp +++ b/source/server/core_server.cpp @@ -23,6 +23,7 @@ #include "version.h" #include "data_moniker_service.h" +#include "sideband_manager.h" using FeatureState = nidevice_grpc::FeatureToggles::FeatureState; using FeatureToggles = nidevice_grpc::FeatureToggles; @@ -67,10 +68,12 @@ static ServerConfiguration GetConfiguration(const std::string& config_file_path) static std::mutex server_mutex; static std::unique_ptr server; static bool shutdown = false; +SidebandManager sideband_manager; static void StopServer() { std::lock_guard guard(server_mutex); + sideband_manager.stop_sideband_threads(); shutdown = true; if (server) { server->Shutdown(); @@ -110,9 +113,7 @@ static void RunServer(const ServerConfiguration& config) } server = builder.BuildAndStart(); if (ni::data_monikers::is_sideband_streaming_enabled(config.feature_toggles)) { - auto sideband_socket_thread = new std::thread(RunSidebandSocketsAccept, config.sideband_address.c_str(), 50055); - // auto sideband_rdma_send_thread = new std::thread(AcceptSidebandRdmaSendRequests); - // auto sideband_rdma_recv_thread = new std::thread(AcceptSidebandRdmaReceiveRequests); + sideband_manager.start_sideband_threads(config.sideband_address.c_str(), 50055); } } diff --git a/source/server/sideband_manager.cpp b/source/server/sideband_manager.cpp new file mode 100644 index 000000000..9872f6f1b --- /dev/null +++ b/source/server/sideband_manager.cpp @@ -0,0 +1,14 @@ +#include "sideband_manager.h" +#include "data_moniker_service.h" + +void SidebandManager::start_sideband_threads(const std::string& address, int port) { + sideband_socket_thread = std::make_unique(RunSidebandSocketsAccept, address.c_str(), port, std::ref(stop_flag)); +} + +void SidebandManager::stop_sideband_threads() { + stop_flag.store(true); + if (sideband_socket_thread && sideband_socket_thread->joinable()) { + sideband_socket_thread->join(); + } + sideband_socket_thread.reset(); +} diff --git a/source/server/sideband_manager.h b/source/server/sideband_manager.h new file mode 100644 index 000000000..3b06e7ec9 --- /dev/null +++ b/source/server/sideband_manager.h @@ -0,0 +1,18 @@ +#ifndef SIDEBAND_MANAGER_H +#define SIDEBAND_MANAGER_H + +#include +#include +#include + +class SidebandManager { +public: + void start_sideband_threads(const std::string& address, int port); + void stop_sideband_threads(); + +private: + std::atomic stop_flag {false}; + std::unique_ptr sideband_socket_thread; +}; + +#endif // SIDEBAND_MANAGER_H \ No newline at end of file From 112050062bd2e058bbd2ba78c0e8c1075756024f Mon Sep 17 00:00:00 2001 From: Ayush Mehra Date: Thu, 28 Nov 2024 10:23:07 +0530 Subject: [PATCH 2/2] update name --- source/server/core_server.cpp | 4 ++-- source/server/sideband_manager.cpp | 4 ++-- source/server/sideband_manager.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/server/core_server.cpp b/source/server/core_server.cpp index dd4f3ee35..330e9f4ef 100644 --- a/source/server/core_server.cpp +++ b/source/server/core_server.cpp @@ -75,7 +75,7 @@ SidebandManager sideband_manager; static void StopServer() { std::lock_guard guard(server_mutex); - sideband_manager.stop_sideband_threads(); + sideband_manager.stop_sideband_thread(); shutdown = true; if (server) { server->Shutdown(); @@ -115,7 +115,7 @@ static void RunServer(const ServerConfiguration& config) } server = builder.BuildAndStart(); if (ni::data_monikers::is_sideband_streaming_enabled(config.feature_toggles)) { - sideband_manager.start_sideband_threads(config.sideband_address.c_str(), config.sideband_port); + sideband_manager.start_sideband_thread(config.sideband_address.c_str(), config.sideband_port); } } diff --git a/source/server/sideband_manager.cpp b/source/server/sideband_manager.cpp index 9872f6f1b..26623e6d7 100644 --- a/source/server/sideband_manager.cpp +++ b/source/server/sideband_manager.cpp @@ -1,11 +1,11 @@ #include "sideband_manager.h" #include "data_moniker_service.h" -void SidebandManager::start_sideband_threads(const std::string& address, int port) { +void SidebandManager::start_sideband_thread(const std::string& address, int port) { sideband_socket_thread = std::make_unique(RunSidebandSocketsAccept, address.c_str(), port, std::ref(stop_flag)); } -void SidebandManager::stop_sideband_threads() { +void SidebandManager::stop_sideband_thread() { stop_flag.store(true); if (sideband_socket_thread && sideband_socket_thread->joinable()) { sideband_socket_thread->join(); diff --git a/source/server/sideband_manager.h b/source/server/sideband_manager.h index 3b06e7ec9..607df115e 100644 --- a/source/server/sideband_manager.h +++ b/source/server/sideband_manager.h @@ -7,8 +7,8 @@ class SidebandManager { public: - void start_sideband_threads(const std::string& address, int port); - void stop_sideband_threads(); + void start_sideband_thread(const std::string& address, int port); + void stop_sideband_thread(); private: std::atomic stop_flag {false};