From 8bcaadaa42e2c91230faf850d10c29703578ef7b Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 30 Jun 2019 18:43:25 -0400 Subject: clean up the bench_network examples --- test/bench_network_tls.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'test/bench_network_tls.cpp') diff --git a/test/bench_network_tls.cpp b/test/bench_network_tls.cpp index 2827a99..b5280b4 100644 --- a/test/bench_network_tls.cpp +++ b/test/bench_network_tls.cpp @@ -103,7 +103,7 @@ struct MyNet: public MsgNetworkByteOp { { if (conn->get_mode() == MyNet::Conn::ACTIVE) { - printf("[%s] Connected, sending hello.\n", this->name.c_str()); + printf("[%s] connected, sending bytes.\n", this->name.c_str()); /* send the first message through this connection */ trigger = [this, conn](ThreadCall::Handle &) { send_msg(MsgBytes(256), salticidae::static_pointer_cast(conn)); @@ -113,11 +113,11 @@ struct MyNet: public MsgNetworkByteOp { tcall.async_call(trigger); } else - printf("[%s] Passively connected, waiting for greetings.\n", this->name.c_str()); + printf("[%s] passively connected, waiting for bytes.\n", this->name.c_str()); } else { - printf("[%s] Disconnected, retrying.\n", this->name.c_str()); + printf("[%s] disconnected, retrying.\n", this->name.c_str()); /* try to reconnect to the same address */ connect(conn->get_addr(), false); } @@ -125,9 +125,7 @@ struct MyNet: public MsgNetworkByteOp { }); } - void on_receive_bytes(MsgBytes &&msg, const conn_t &conn) { - nrecv++; - } + void on_receive_bytes(MsgBytes &&msg, const conn_t &conn) { nrecv++; } }; salticidae::EventContext ec; @@ -139,20 +137,16 @@ int main() { alice->start(); alice->listen(alice_addr); salticidae::EventContext tec; - salticidae::BoxObj tcall = new ThreadCall(tec); - std::thread bob_thread([&tec]() { - MyNet bob(tec, "Bob"); + MyNet bob(tec, "Bob"); + std::thread bob_thread([&]() { bob.start(); bob.connect(alice_addr); - try { - tec.dispatch(); - } catch (std::exception &) {} + tec.dispatch(); }); auto shutdown = [&](int) { - tcall->async_call([&](salticidae::ThreadCall::Handle &) { + bob.tcall.async_call([&](salticidae::ThreadCall::Handle &) { tec.stop(); }); - alice = nullptr; ec.stop(); bob_thread.join(); }; -- cgit v1.2.3