From 60c4af2602e18933f2b795500f44c6613c852f45 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 19 Nov 2018 22:19:56 -0500 Subject: correctly use std::forward --- include/salticidae/event.h | 2 +- include/salticidae/network.h | 14 +++++++------- src/conn.cpp | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/salticidae/event.h b/include/salticidae/event.h index 4a1a410..ca48e69 100644 --- a/include/salticidae/event.h +++ b/include/salticidae/event.h @@ -335,7 +335,7 @@ class ThreadCall { notifier->notify(std::move(result)); } template - void set_result(T data) { + void set_result(T &&data) { result = Result(new T(std::forward(data)), [](void *ptr) {delete static_cast(ptr);}); } diff --git a/include/salticidae/network.h b/include/salticidae/network.h index c74ba7d..f2b99b3 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -192,7 +192,7 @@ class MsgNetwork: public ConnPool { } template - void send_msg(const MsgType &msg, const conn_t &conn); + void send_msg(MsgType &&msg, const conn_t &conn); using ConnPool::listen; #ifdef SALTICIDAE_MSG_STAT msg_stat_by_opcode_t &get_sent_by_opcode() const { @@ -243,7 +243,7 @@ class ClientNetwork: public MsgNetwork { MsgNet(ec, config) {} template - void send_msg(MsgType msg, const NetAddr &addr); + void send_msg(MsgType &&msg, const NetAddr &addr); }; class PeerNetworkError: public ConnPoolError { @@ -429,7 +429,7 @@ class PeerNetwork: public MsgNetwork { const conn_t get_peer_conn(const NetAddr &paddr) const; using MsgNet::send_msg; template - void send_msg(MsgType msg, const NetAddr &paddr); + void send_msg(MsgType &&msg, const NetAddr &paddr); void listen(NetAddr listen_addr); bool has_peer(const NetAddr &paddr) const; conn_t connect(const NetAddr &addr) = delete; @@ -472,8 +472,8 @@ void MsgNetwork::Conn::on_read() { template template -void MsgNetwork::send_msg(const MsgType &_msg, const conn_t &conn) { - Msg msg(_msg); +void MsgNetwork::send_msg(MsgType &&_msg, const conn_t &conn) { + Msg msg(std::forward(_msg)); bytearray_t msg_data = msg.serialize(); SALTICIDAE_LOG_DEBUG("wrote message %s to %s", std::string(msg).c_str(), @@ -708,7 +708,7 @@ bool PeerNetwork::has_peer(const NetAddr &paddr) const { template template -void PeerNetwork::send_msg(MsgType msg, const NetAddr &paddr) { +void PeerNetwork::send_msg(MsgType &&msg, const NetAddr &paddr) { this->disp_tcall->async_call( [this, msg=std::forward(msg), paddr](ThreadCall::Handle &h) { auto it = id2peer.find(paddr); @@ -740,7 +740,7 @@ void ClientNetwork::Conn::on_teardown() { template template -void ClientNetwork::send_msg(MsgType msg, const NetAddr &addr) { +void ClientNetwork::send_msg(MsgType &&msg, const NetAddr &addr) { this->disp_tcall->async_call( [this, addr, msg=std::forward(msg)](ThreadCall::Handle &h) { auto it = addr2conn.find(addr); diff --git a/src/conn.cpp b/src/conn.cpp index b131684..51a5346 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -304,7 +304,6 @@ void ConnPool::del_conn(const conn_t &conn) { update_conn(conn, false); conn->release_self(); /* remove the self-cycle */ ::close(conn->fd); - SALTICIDAE_LOG_INFO("remove_conn: %s", std::string(*conn).c_str()); conn->fd = -1; } } -- cgit v1.2.3-70-g09d2