diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/bench_network.cpp | 20 | ||||
-rw-r--r-- | test/test_p2p_stress.cpp | 8 | ||||
-rw-r--r-- | test/test_queue.cpp | 6 |
3 files changed, 18 insertions, 16 deletions
diff --git a/test/bench_network.cpp b/test/bench_network.cpp index b0856b8..be90e2a 100644 --- a/test/bench_network.cpp +++ b/test/bench_network.cpp @@ -42,7 +42,7 @@ using salticidae::MsgNetwork; using salticidae::htole; using salticidae::letoh; using salticidae::bytearray_t; -using salticidae::Event; +using salticidae::TimerEvent; using std::placeholders::_1; using std::placeholders::_2; using opcode_t = uint8_t; @@ -71,8 +71,8 @@ using MsgNetworkByteOp = MsgNetwork<opcode_t>; struct MyNet: public MsgNetworkByteOp { const std::string name; const NetAddr peer; - Event ev_period_send; - Event ev_period_stat; + TimerEvent ev_period_send; + TimerEvent ev_period_stat; size_t nrecv; MyNet(const salticidae::EventContext &ec, @@ -82,17 +82,17 @@ struct MyNet: public MsgNetworkByteOp { MsgNetworkByteOp(ec, MsgNetworkByteOp::Config()), name(name), peer(peer), - ev_period_stat(ec, -1, [this, stat_timeout](int, short) { + ev_period_stat(ec, [this, stat_timeout](TimerEvent &) { SALTICIDAE_LOG_INFO("%.2f mps\n", nrecv / (double)stat_timeout); nrecv = 0; - ev_period_stat.add_with_timeout(stat_timeout, 0); + ev_period_stat.add(stat_timeout); }), nrecv(0) { /* message handler could be a bound method */ reg_handler(salticidae::generic_bind( &MyNet::on_receive_bytes, this, _1, _2)); if (stat_timeout > 0) - ev_period_stat.add_with_timeout(0, 0); + ev_period_stat.add(0); } struct Conn: public MsgNetworkByteOp::Conn { @@ -109,12 +109,12 @@ struct MyNet: public MsgNetworkByteOp { printf("[%s] Connected, sending hello.\n", net->name.c_str()); /* send the first message through this connection */ - net->ev_period_send = Event(net->ec, -1, - [net, conn = self()](int, short) { + net->ev_period_send = TimerEvent(net->ec, + [net, conn = self()](TimerEvent &) { net->send_msg(MsgBytes(256), conn); - net->ev_period_send.add_with_timeout(0, 0); + net->ev_period_send.add(0); }); - net->ev_period_send.add_with_timeout(0, 0); + net->ev_period_send.add(0); } else diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp index b272742..70e3444 100644 --- a/test/test_p2p_stress.cpp +++ b/test/test_p2p_stress.cpp @@ -36,7 +36,7 @@ using salticidae::NetAddr; using salticidae::DataStream; using salticidae::MsgNetwork; using salticidae::ConnPool; -using salticidae::Event; +using salticidae::TimerEvent; using salticidae::EventContext; using salticidae::htole; using salticidae::letoh; @@ -78,7 +78,7 @@ using MyNet = salticidae::PeerNetwork<uint8_t>; std::vector<NetAddr> addrs; struct TestContext { - Event timer; + TimerEvent timer; int state; uint256_t hash; size_t ncompleted; @@ -130,7 +130,7 @@ void install_proto(AppContext &app, const size_t &seg_buff_size) { { send_rand(tc.state, conn); tc.state = -1; - tc.timer = Event(ec, -1, [&, conn](int, int) { + tc.timer = TimerEvent(ec, [&, conn](TimerEvent &) { tc.ncompleted++; net.terminate(conn); std::string s; @@ -139,7 +139,7 @@ void install_proto(AppContext &app, const size_t &seg_buff_size) { SALTICIDAE_LOG_INFO("%d completed:%s", ntohs(app.addr.port), s.c_str()); }); double t = salticidae::gen_rand_timeout(10); - tc.timer.add_with_timeout(t, 0); + tc.timer.add(t); SALTICIDAE_LOG_INFO("rand-bomboard phase, ending in %.2f secs", t); } else if (tc.state == -1) diff --git a/test/test_queue.cpp b/test/test_queue.cpp index 41c6f88..7b06951 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -4,6 +4,8 @@ #include "salticidae/event.h" +using salticidae::TimerEvent; + void test_mpsc(int nproducers = 16, int nops = 100000, size_t burst_size = 128) { size_t total = nproducers * nops; salticidae::EventContext ec; @@ -23,10 +25,10 @@ void test_mpsc(int nproducers = 16, int nops = 100000, size_t burst_size = 128) }); std::vector<std::thread> producers; std::thread consumer([&collected, total, &ec]() { - salticidae::Event timer(ec, -1, [&ec, &collected, total](int, short) { + TimerEvent timer(ec, [&ec, &collected, total](TimerEvent &) { if (collected.load() == total) ec.stop(); }); - timer.add_with_timeout(1, 0); + timer.add(1); ec.dispatch(); }); for (int i = 0; i < nproducers; i++) |