aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2018-08-03 13:52:09 -0400
committerDeterminant <[email protected]>2018-08-03 13:52:09 -0400
commit3f1c768e2d5b5e51dec08499d6a877220f33d7a6 (patch)
tree208dfc45136706e395d16a37bf2bbf77dd548d98
parent37dc1f5bfe6630c224d1b131562166ab5bdd9976 (diff)
rename handler_bind and move to type.h
-rw-r--r--README.rst2
-rw-r--r--include/salticidae/network.h9
-rw-r--r--include/salticidae/type.h5
-rw-r--r--test/bench_network.cpp4
-rw-r--r--test/test_network.cpp2
5 files changed, 11 insertions, 11 deletions
diff --git a/README.rst b/README.rst
index 06fa050..03fef81 100644
--- a/README.rst
+++ b/README.rst
@@ -132,7 +132,7 @@ Example (MsgNetwork layer)
name(name),
peer(peer) {
/* message handler could be a bound method */
- reg_handler(salticidae::handler_bind(
+ reg_handler(salticidae::generic_bind(
&MyNet::on_receive_hello, this, _1, _2));
reg_conn_handler([this](ConnPool::Conn &conn) {
diff --git a/include/salticidae/network.h b/include/salticidae/network.h
index c7b7f66..63c83be 100644
--- a/include/salticidae/network.h
+++ b/include/salticidae/network.h
@@ -32,11 +32,6 @@
namespace salticidae {
-template<typename ClassType, typename ReturnType, typename... Args, typename... FArgs>
-inline auto handler_bind(ReturnType(ClassType::* f)(Args...), FArgs&&... fargs) {
- return std::function<ReturnType(Args...)>(std::bind(f, std::forward<FArgs>(fargs)...));
-}
-
/** Network of nodes who can send async messages. */
template<typename OpcodeType>
class MsgNetwork: public ConnPool {
@@ -527,8 +522,8 @@ template<typename O, O _, O __>
void PeerNetwork<O, _, __>::listen(NetAddr listen_addr) {
MsgNet::listen(listen_addr);
listen_port = listen_addr.port;
- this->reg_handler(handler_bind(&PeerNetwork::msg_ping, this, _1, _2));
- this->reg_handler(handler_bind(&PeerNetwork::msg_pong, this, _1, _2));
+ this->reg_handler(generic_bind(&PeerNetwork::msg_ping, this, _1, _2));
+ this->reg_handler(generic_bind(&PeerNetwork::msg_pong, this, _1, _2));
}
template<typename O, O _, O __>
diff --git a/include/salticidae/type.h b/include/salticidae/type.h
index 13d3071..c454265 100644
--- a/include/salticidae/type.h
+++ b/include/salticidae/type.h
@@ -79,6 +79,11 @@ struct log2<1> {
enum { value = 0 };
};
+template<typename ClassType, typename ReturnType, typename... Args, typename... FArgs>
+inline auto generic_bind(ReturnType(ClassType::* f)(Args...), FArgs&&... fargs) {
+ return std::function<ReturnType(Args...)>(std::bind(f, std::forward<FArgs>(fargs)...));
+}
+
}
#endif
diff --git a/test/bench_network.cpp b/test/bench_network.cpp
index bd31ee0..1185c0d 100644
--- a/test/bench_network.cpp
+++ b/test/bench_network.cpp
@@ -89,7 +89,7 @@ struct MyNet: public MsgNetworkByteOp {
}),
nrecv(0) {
/* message handler could be a bound method */
- reg_handler(salticidae::handler_bind(
+ reg_handler(salticidae::generic_bind(
&MyNet::on_receive_bytes, this, _1, _2));
if (stat_timeout > 0)
ev_period_stat.add_with_timeout(0);
@@ -123,7 +123,7 @@ struct MyNet: public MsgNetworkByteOp {
}
void on_teardown() override {
auto net = get_net();
- net->ev_period_send = Event();
+ net->ev_period_send.clear();
printf("[%s] Disconnected, retrying.\n", net->name.c_str());
/* try to reconnect to the same address */
net->connect(get_addr());
diff --git a/test/test_network.cpp b/test/test_network.cpp
index e5d2b1d..c4fe2e2 100644
--- a/test/test_network.cpp
+++ b/test/test_network.cpp
@@ -86,7 +86,7 @@ struct MyNet: public MsgNetworkByteOp {
name(name),
peer(peer) {
/* message handler could be a bound method */
- reg_handler(salticidae::handler_bind(
+ reg_handler(salticidae::generic_bind(
&MyNet::on_receive_hello, this, _1, _2));
reg_conn_handler([this](ConnPool::Conn &conn) {