Skip to content

Commit 436040b

Browse files
committed
iox-#2408 server node example waiting for roudi to start, remove Node forward declaration in posh_runtime
1 parent fd27126 commit 436040b

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

iceoryx_examples/experimental/node/iox_cpp_node_server.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#include <iostream>
2626

2727
constexpr char APP_NAME[] = "iox-cpp-node-server";
28+
volatile bool keepRunning = {true};
29+
30+
static void signalHandler(int sig [[maybe_unused]])
31+
{
32+
keepRunning = false;
33+
}
2834

2935
//! [request callback]
3036
void onRequestReceived(iox::popo::Server<AddRequest, AddResponse>* server)
@@ -52,16 +58,23 @@ void onRequestReceived(iox::popo::Server<AddRequest, AddResponse>* server)
5258

5359
int main()
5460
{
61+
auto sigTermGuard =
62+
iox::registerSignalHandler(iox::PosixSignal::TERM, signalHandler).expect("failed to register SIGTERM");
63+
auto sigIntGuard =
64+
iox::registerSignalHandler(iox::PosixSignal::INT, signalHandler).expect("failed to register SIGINT");
5565
//! [create the node]
56-
auto node_result = iox::posh::experimental::NodeBuilder(APP_NAME)
57-
.domain_id_from_env_or_default()
58-
.roudi_registration_timeout(iox::units::Duration::fromSeconds(1))
59-
.create();
60-
if (node_result.has_error())
66+
auto node_result = iox::posh::experimental::NodeBuilder(APP_NAME).domain_id_from_env_or_default().create();
67+
68+
while (keepRunning && node_result.has_error())
6169
{
6270
std::cout << "Could not create the node!" << std::endl;
63-
return -1;
71+
72+
node_result = iox::posh::experimental::NodeBuilder(APP_NAME)
73+
.domain_id_from_env_or_default()
74+
.roudi_registration_timeout(iox::units::Duration::fromSeconds(1))
75+
.create();
6476
}
77+
6578
auto node = std::move(node_result.value());
6679
//! [create the node]
6780

iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
#include "iox/optional.hpp"
3535
#include "iox/scope_guard.hpp"
3636

37-
namespace iox::posh::experimental
38-
{
39-
class Node;
40-
}
41-
4237
namespace iox
4338
{
4439
namespace roudi_env

0 commit comments

Comments
 (0)