Skip to content

Commit

Permalink
examples: don't exit too early (#2478)
Browse files Browse the repository at this point in the history
Otherwise, we'd have to use attach.
  • Loading branch information
julianoes authored Dec 18, 2024
1 parent c7b7bd4 commit fa2c26f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions examples/start_stop_server/start_stop_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

#include <mavsdk/mavsdk.h>
#include <mavsdk/mavsdk_server/mavsdk_server_api.h>
#include <atomic>
#include <iostream>
#include <chrono>
#include <csignal>
#include <thread>

using namespace mavsdk;

static struct MavsdkServer* mavsdk_server;
static std::atomic<bool> _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[])
Expand All @@ -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;
Expand Down

0 comments on commit fa2c26f

Please sign in to comment.