From d542aa0b24d5607ee066a2a50f5e29064c1aaef7 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 1 Aug 2018 14:15:43 -0400 Subject: ... --- test/bench_network.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/bench_network.cpp b/test/bench_network.cpp index 19f0dd9..bd31ee0 100644 --- a/test/bench_network.cpp +++ b/test/bench_network.cpp @@ -26,6 +26,7 @@ #include #include #include +#include /* disable SHA256 checksum */ #define SALTICIDAE_NOCHECKSUM @@ -142,6 +143,10 @@ salticidae::EventContext ec; NetAddr alice_addr("127.0.0.1:1234"); NetAddr bob_addr("127.0.0.1:1235"); +void signal_handler(int) { + throw salticidae::SalticidaeError("got terminal signal"); +} + int main() { /* test two nodes */ MyNet alice(ec, "Alice", bob_addr, 10); @@ -150,9 +155,18 @@ int main() { salticidae::EventContext ec; MyNet bob(ec, "Bob", alice_addr); bob.connect(alice_addr); - ec.dispatch(); + try { + ec.dispatch(); + } catch (std::exception &) {} }); - - ec.dispatch(); + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + try { + ec.dispatch(); + } catch (std::exception &e) { + pthread_kill(bob_thread.native_handle(), SIGINT); + bob_thread.join(); + SALTICIDAE_LOG_INFO("exception: %s", e.what()); + } return 0; } -- cgit v1.2.3-70-g09d2