From fa2c26fba8b698dab20df21a5a9b96e2c5673af4 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 19 Dec 2024 12:28:16 +1300 Subject: [PATCH] examples: don't exit too early (#2478) Otherwise, we'd have to use attach. --- .../start_stop_server/start_stop_server.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/start_stop_server/start_stop_server.cpp b/examples/start_stop_server/start_stop_server.cpp index ff7286a67..ce692625f 100644 --- a/examples/start_stop_server/start_stop_server.cpp +++ b/examples/start_stop_server/start_stop_server.cpp @@ -4,18 +4,20 @@ #include #include +#include #include +#include #include +#include using namespace mavsdk; -static struct MavsdkServer* mavsdk_server; +static std::atomic _should_stop{false}; void signal_handler(int sig) { std::cout << "Received signal " << sig << std::endl; - - mavsdk_server_stop(mavsdk_server); + _should_stop.store(true); } int main(int argc, char* argv[]) @@ -27,9 +29,18 @@ int main(int argc, char* argv[]) signal(SIGINT, signal_handler); + MavsdkServer* mavsdk_server; + mavsdk_server_init(&mavsdk_server); + + // This returns when a system has been discovered. mavsdk_server_run(mavsdk_server, argv[1], 50051); + while (!_should_stop.load()) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + mavsdk_server_stop(mavsdk_server); mavsdk_server_destroy(mavsdk_server); return 0;