aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-30 18:43:25 -0400
committerDeterminant <[email protected]>2019-06-30 18:43:25 -0400
commit8bcaadaa42e2c91230faf850d10c29703578ef7b (patch)
treeae303593847d805594147ee66fddb2a11dac3a39
parent624550d7e1c032a4d3896ba002aa3ecb895f447c (diff)
clean up the bench_network examples
-rw-r--r--test/bench_network.cpp26
-rw-r--r--test/bench_network_tls.cpp22
2 files changed, 19 insertions, 29 deletions
diff --git a/test/bench_network.cpp b/test/bench_network.cpp
index 82c6268..5575a66 100644
--- a/test/bench_network.cpp
+++ b/test/bench_network.cpp
@@ -80,7 +80,9 @@ struct MyNet: public MsgNetworkByteOp {
const std::string name,
double stat_timeout = -1):
MsgNetworkByteOp(ec, MsgNetworkByteOp::Config(
- ConnPool::Config().queue_capacity(65536)).burst_size(1000)),
+ ConnPool::Config()
+ .queue_capacity(65536)
+ ).burst_size(1000)),
name(name),
ev_period_stat(ec, [this, stat_timeout](TimerEvent &) {
SALTICIDAE_LOG_INFO("%.2f mps", nrecv / (double)stat_timeout);
@@ -99,7 +101,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>(conn));
@@ -109,11 +111,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);
}
@@ -121,9 +123,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;
@@ -135,20 +135,16 @@ int main() {
alice->start();
alice->listen(alice_addr);
salticidae::EventContext tec;
- salticidae::BoxObj<ThreadCall> 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();
};
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>(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<ThreadCall> 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();
};