diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 3692e45a9..1875d1461 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -1269,7 +1269,8 @@ bool Connection::deletePeer(session_t peer_id, bool timeout) return false; peer = m_peers[peer_id]; m_peers.erase(peer_id); - m_peer_ids.remove(peer_id); + auto it = std::find(m_peer_ids.begin(), m_peer_ids.end(), peer_id); + m_peer_ids.erase(it); } Address peer_address; diff --git a/src/network/connection.h b/src/network/connection.h index 47b0805ce..2dc6d4397 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "networkprotocol.h" #include #include -#include +#include #include class NetworkPacket; @@ -795,7 +795,7 @@ protected: void PrintInfo(std::ostream &out); - std::list getPeerIDs() + std::vector getPeerIDs() { MutexAutoLock peerlock(m_peers_mutex); return m_peer_ids; @@ -816,7 +816,7 @@ private: u32 m_protocol_id; std::map m_peers; - std::list m_peer_ids; + std::vector m_peer_ids; std::mutex m_peers_mutex; std::unique_ptr m_sendThread; diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index 9a6617a1c..28ed798d9 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -144,7 +144,7 @@ void ConnectionSendThread::Trigger() bool ConnectionSendThread::packetsQueued() { - std::list peerIds = m_connection->getPeerIDs(); + std::vector peerIds = m_connection->getPeerIDs(); if (!m_outgoing_queue.empty() && !peerIds.empty()) return true; @@ -171,8 +171,8 @@ bool ConnectionSendThread::packetsQueued() void ConnectionSendThread::runTimeouts(float dtime) { - std::list timeouted_peers; - std::list peerIds = m_connection->getPeerIDs(); + std::vector timeouted_peers; + std::vector peerIds = m_connection->getPeerIDs(); for (session_t &peerId : peerIds) { PeerHelper peer = m_connection->getPeerNoEx(peerId); @@ -548,7 +548,7 @@ void ConnectionSendThread::disconnect() // Send to all - std::list peerids = m_connection->getPeerIDs(); + std::vector peerids = m_connection->getPeerIDs(); for (session_t peerid : peerids) { sendAsPacket(peerid, 0, data, false); @@ -620,7 +620,7 @@ void ConnectionSendThread::sendReliable(ConnectionCommand &c) void ConnectionSendThread::sendToAll(u8 channelnum, const SharedBuffer &data) { - std::list peerids = m_connection->getPeerIDs(); + std::vector peerids = m_connection->getPeerIDs(); for (session_t peerid : peerids) { send(peerid, channelnum, data); @@ -629,7 +629,7 @@ void ConnectionSendThread::sendToAll(u8 channelnum, const SharedBuffer &data void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c) { - std::list peerids = m_connection->getPeerIDs(); + std::vector peerids = m_connection->getPeerIDs(); for (session_t peerid : peerids) { PeerHelper peer = m_connection->getPeerNoEx(peerid); @@ -643,8 +643,8 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c) void ConnectionSendThread::sendPackets(float dtime) { - std::list peerIds = m_connection->getPeerIDs(); - std::list pendingDisconnect; + std::vector peerIds = m_connection->getPeerIDs(); + std::vector pendingDisconnect; std::map pending_unreliable; const unsigned int peer_packet_quota = m_iteration_packets_avaialble @@ -843,13 +843,11 @@ void *ConnectionReceiveThread::run() if (debug_print_timer > 20.0) { debug_print_timer -= 20.0; - std::list peerids = m_connection->getPeerIDs(); + std::vector peerids = m_connection->getPeerIDs(); - for (std::list::iterator i = peerids.begin(); - i != peerids.end(); - i++) + for (auto id : peerids) { - PeerHelper peer = m_connection->getPeerNoEx(*i); + PeerHelper peer = m_connection->getPeerNoEx(id); if (!peer) continue; @@ -1039,7 +1037,7 @@ void ConnectionReceiveThread::receive(SharedBuffer &packetdata, bool ConnectionReceiveThread::getFromBuffers(session_t &peer_id, SharedBuffer &dst) { - std::list peerids = m_connection->getPeerIDs(); + std::vector peerids = m_connection->getPeerIDs(); for (session_t peerid : peerids) { PeerHelper peer = m_connection->getPeerNoEx(peerid);