From a9005311f51a250db26c966ce5fd4a7ba7d76fab Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 14 Jun 2019 17:08:33 -0400 Subject: minor API change --- test/test_msgnet_c.c | 7 +++++++ test/test_p2p.cpp | 9 +++++++-- test/test_p2p_stress.cpp | 10 +++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/test_msgnet_c.c b/test/test_msgnet_c.c index b2fb35a..c2fb492 100644 --- a/test/test_msgnet_c.c +++ b/test/test_msgnet_c.c @@ -139,6 +139,13 @@ void conn_handler(const msgnetwork_conn_t *conn, bool connected, void *userdata) } } +void error_handler(const SalticidaeCError *err, bool fatal, void *userdata) { + MyNet *n = (MyNet *)userdata; + printf("[%s] Captured %s error during an async call: %s\n", + n->name, fatal ? "fatal" : "recoverable", + salticidae_strerror(err->code)); +} + MyNet gen_mynet(const eventcontext_t *ec, const char *name) { MyNet res; diff --git a/test/test_p2p.cpp b/test/test_p2p.cpp index 6d311a6..14304eb 100644 --- a/test/test_p2p.cpp +++ b/test/test_p2p.cpp @@ -79,8 +79,13 @@ struct Net { net->reg_handler([this](const MsgText &msg, const PeerNetwork::conn_t &) { fprintf(stdout, "net %lu: peer %lu says %s\n", this->id, msg.id, msg.text.c_str()); }); - net->reg_error_handler([this](const std::exception &err, bool fatal) { - fprintf(stdout, "net %lu: captured %s error during an async call: %s\n", this->id, fatal ? "fatal" : "recoverable", err.what()); + net->reg_error_handler([this](const std::exception_ptr _err, bool fatal) { + try { + std::rethrow_exception(_err); + } catch (const std::exception &err) { + fprintf(stdout, "net %lu: captured %s error during an async call: %s\n", + this->id, fatal ? "fatal" : "recoverable", err.what()); + } }); net->reg_unknown_peer_handler([this](const NetAddr &addr) { fprintf(stdout, "net %lu: unknown peer attempts to connnect %s\n", this->id, std::string(addr).c_str()); diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp index 3a71660..92e5bb4 100644 --- a/test/test_p2p_stress.cpp +++ b/test/test_p2p_stress.cpp @@ -114,9 +114,13 @@ void install_proto(AppContext &app, const size_t &seg_buff_size) { } } }); - net.reg_error_handler([ec](const std::exception &err, bool fatal) { - SALTICIDAE_LOG_WARN("main thread captured %s error: %s", - fatal ? "fatal" : "recoverable", err.what()); + net.reg_error_handler([ec](const std::exception_ptr _err, bool fatal) { + try { + std::rethrow_exception(_err); + } catch (const std::exception & err) { + SALTICIDAE_LOG_WARN("main thread captured %s error: %s", + fatal ? "fatal" : "recoverable", err.what()); + } }); net.reg_handler([&](MsgRand &&msg, const MyNet::conn_t &conn) { uint256_t hash = salticidae::get_hash(msg.bytes); -- cgit v1.2.3