aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2018-08-01 14:15:43 -0400
committerDeterminant <[email protected]>2018-08-01 14:15:43 -0400
commitd542aa0b24d5607ee066a2a50f5e29064c1aaef7 (patch)
tree3ea26f118645e67f4969a723dad60db71b519d63 /test
parentbc078abd9d5fcc420dfbcda06869a95aba39b1ea (diff)
...
Diffstat (limited to 'test')
-rw-r--r--test/bench_network.cpp20
1 files changed, 17 insertions, 3 deletions
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 <string>
#include <functional>
#include <thread>
+#include <signal.h>
/* 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;
}