diff options
author | Determinant <ted.sybil@gmail.com> | 2018-11-18 16:24:30 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-11-18 16:24:30 -0500 |
commit | 161d969e0eabfecccd69a6b9ed2d03919cf89cb5 (patch) | |
tree | 60008191c4320a8b4c5ae31773d70f996d3548f7 /test/test_p2p.cpp | |
parent | 39f6d6ac46d440aa68e7b1a2f2e4eb629356af34 (diff) |
improve the test programsmultiloops
Diffstat (limited to 'test/test_p2p.cpp')
-rw-r--r-- | test/test_p2p.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/test/test_p2p.cpp b/test/test_p2p.cpp index 1c37aa6..e884930 100644 --- a/test/test_p2p.cpp +++ b/test/test_p2p.cpp @@ -82,25 +82,20 @@ std::vector<NetAddr> addrs = { NetAddr("127.0.0.1:12348") }; -void signal_handler(int) { - throw salticidae::SalticidaeError("got termination signal"); -} +salticidae::EventContext ec; +MyNet net(ec, MyNet::Config().conn_timeout(5).ping_period(2)); int main(int argc, char **argv) { - signal(SIGTERM, signal_handler); - signal(SIGINT, signal_handler); - - salticidae::EventContext ec; - /* test two nodes */ - MyNet net(ec, MyNet::Config().conn_timeout(5).ping_period(2)); - - try { - int i; - net.start(); - net.listen(addrs[i = atoi(argv[1])]); - for (int j = 0; j < addrs.size(); j++) - if (i != j) net.add_peer(addrs[j]); - ec.dispatch(); - } catch (salticidae::SalticidaeError &e) {} + int i; + net.start(); + net.listen(addrs[i = atoi(argv[1])]); + for (int j = 0; j < addrs.size(); j++) + if (i != j) net.add_peer(addrs[j]); + auto shutdown = [&](int) {ec.stop();}; + salticidae::SigEvent ev_sigint(ec, shutdown); + salticidae::SigEvent ev_sigterm(ec, shutdown); + ev_sigint.add(SIGINT); + ev_sigterm.add(SIGTERM); + ec.dispatch(); return 0; } |