diff options
-rw-r--r-- | include/salticidae/event.h | 2 | ||||
-rw-r--r-- | include/salticidae/network.h | 14 | ||||
-rw-r--r-- | 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<typename T> - void set_result(T data) { + void set_result(T &&data) { result = Result(new T(std::forward<T>(data)), [](void *ptr) {delete static_cast<T *>(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<typename MsgType> - 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<OpcodeType> { MsgNet(ec, config) {} template<typename MsgType> - 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<OpcodeType> { const conn_t get_peer_conn(const NetAddr &paddr) const; using MsgNet::send_msg; template<typename MsgType> - 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<OpcodeType>::Conn::on_read() { template<typename OpcodeType> template<typename MsgType> -void MsgNetwork<OpcodeType>::send_msg(const MsgType &_msg, const conn_t &conn) { - Msg msg(_msg); +void MsgNetwork<OpcodeType>::send_msg(MsgType &&_msg, const conn_t &conn) { + Msg msg(std::forward<MsgType>(_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<O, _, __>::has_peer(const NetAddr &paddr) const { template<typename O, O _, O __> template<typename MsgType> -void PeerNetwork<O, _, __>::send_msg(MsgType msg, const NetAddr &paddr) { +void PeerNetwork<O, _, __>::send_msg(MsgType &&msg, const NetAddr &paddr) { this->disp_tcall->async_call( [this, msg=std::forward<MsgType>(msg), paddr](ThreadCall::Handle &h) { auto it = id2peer.find(paddr); @@ -740,7 +740,7 @@ void ClientNetwork<OpcodeType>::Conn::on_teardown() { template<typename OpcodeType> template<typename MsgType> -void ClientNetwork<OpcodeType>::send_msg(MsgType msg, const NetAddr &addr) { +void ClientNetwork<OpcodeType>::send_msg(MsgType &&msg, const NetAddr &addr) { this->disp_tcall->async_call( [this, addr, msg=std::forward<MsgType>(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; } } |