forked from Mirrorlandia_minetest/minetest
Replace std::list<session_t> in networking code (#10215)
This commit is contained in:
parent
76afde861d
commit
8ca602150d
@ -1269,7 +1269,8 @@ bool Connection::deletePeer(session_t peer_id, bool timeout)
|
|||||||
return false;
|
return false;
|
||||||
peer = m_peers[peer_id];
|
peer = m_peers[peer_id];
|
||||||
m_peers.erase(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;
|
Address peer_address;
|
||||||
|
@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "networkprotocol.h"
|
#include "networkprotocol.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <list>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class NetworkPacket;
|
class NetworkPacket;
|
||||||
@ -795,7 +795,7 @@ protected:
|
|||||||
|
|
||||||
void PrintInfo(std::ostream &out);
|
void PrintInfo(std::ostream &out);
|
||||||
|
|
||||||
std::list<session_t> getPeerIDs()
|
std::vector<session_t> getPeerIDs()
|
||||||
{
|
{
|
||||||
MutexAutoLock peerlock(m_peers_mutex);
|
MutexAutoLock peerlock(m_peers_mutex);
|
||||||
return m_peer_ids;
|
return m_peer_ids;
|
||||||
@ -816,7 +816,7 @@ private:
|
|||||||
u32 m_protocol_id;
|
u32 m_protocol_id;
|
||||||
|
|
||||||
std::map<session_t, Peer *> m_peers;
|
std::map<session_t, Peer *> m_peers;
|
||||||
std::list<session_t> m_peer_ids;
|
std::vector<session_t> m_peer_ids;
|
||||||
std::mutex m_peers_mutex;
|
std::mutex m_peers_mutex;
|
||||||
|
|
||||||
std::unique_ptr<ConnectionSendThread> m_sendThread;
|
std::unique_ptr<ConnectionSendThread> m_sendThread;
|
||||||
|
@ -144,7 +144,7 @@ void ConnectionSendThread::Trigger()
|
|||||||
|
|
||||||
bool ConnectionSendThread::packetsQueued()
|
bool ConnectionSendThread::packetsQueued()
|
||||||
{
|
{
|
||||||
std::list<session_t> peerIds = m_connection->getPeerIDs();
|
std::vector<session_t> peerIds = m_connection->getPeerIDs();
|
||||||
|
|
||||||
if (!m_outgoing_queue.empty() && !peerIds.empty())
|
if (!m_outgoing_queue.empty() && !peerIds.empty())
|
||||||
return true;
|
return true;
|
||||||
@ -171,8 +171,8 @@ bool ConnectionSendThread::packetsQueued()
|
|||||||
|
|
||||||
void ConnectionSendThread::runTimeouts(float dtime)
|
void ConnectionSendThread::runTimeouts(float dtime)
|
||||||
{
|
{
|
||||||
std::list<session_t> timeouted_peers;
|
std::vector<session_t> timeouted_peers;
|
||||||
std::list<session_t> peerIds = m_connection->getPeerIDs();
|
std::vector<session_t> peerIds = m_connection->getPeerIDs();
|
||||||
|
|
||||||
for (session_t &peerId : peerIds) {
|
for (session_t &peerId : peerIds) {
|
||||||
PeerHelper peer = m_connection->getPeerNoEx(peerId);
|
PeerHelper peer = m_connection->getPeerNoEx(peerId);
|
||||||
@ -548,7 +548,7 @@ void ConnectionSendThread::disconnect()
|
|||||||
|
|
||||||
|
|
||||||
// Send to all
|
// Send to all
|
||||||
std::list<session_t> peerids = m_connection->getPeerIDs();
|
std::vector<session_t> peerids = m_connection->getPeerIDs();
|
||||||
|
|
||||||
for (session_t peerid : peerids) {
|
for (session_t peerid : peerids) {
|
||||||
sendAsPacket(peerid, 0, data, false);
|
sendAsPacket(peerid, 0, data, false);
|
||||||
@ -620,7 +620,7 @@ void ConnectionSendThread::sendReliable(ConnectionCommand &c)
|
|||||||
|
|
||||||
void ConnectionSendThread::sendToAll(u8 channelnum, const SharedBuffer<u8> &data)
|
void ConnectionSendThread::sendToAll(u8 channelnum, const SharedBuffer<u8> &data)
|
||||||
{
|
{
|
||||||
std::list<session_t> peerids = m_connection->getPeerIDs();
|
std::vector<session_t> peerids = m_connection->getPeerIDs();
|
||||||
|
|
||||||
for (session_t peerid : peerids) {
|
for (session_t peerid : peerids) {
|
||||||
send(peerid, channelnum, data);
|
send(peerid, channelnum, data);
|
||||||
@ -629,7 +629,7 @@ void ConnectionSendThread::sendToAll(u8 channelnum, const SharedBuffer<u8> &data
|
|||||||
|
|
||||||
void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
|
void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
|
||||||
{
|
{
|
||||||
std::list<session_t> peerids = m_connection->getPeerIDs();
|
std::vector<session_t> peerids = m_connection->getPeerIDs();
|
||||||
|
|
||||||
for (session_t peerid : peerids) {
|
for (session_t peerid : peerids) {
|
||||||
PeerHelper peer = m_connection->getPeerNoEx(peerid);
|
PeerHelper peer = m_connection->getPeerNoEx(peerid);
|
||||||
@ -643,8 +643,8 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
|
|||||||
|
|
||||||
void ConnectionSendThread::sendPackets(float dtime)
|
void ConnectionSendThread::sendPackets(float dtime)
|
||||||
{
|
{
|
||||||
std::list<session_t> peerIds = m_connection->getPeerIDs();
|
std::vector<session_t> peerIds = m_connection->getPeerIDs();
|
||||||
std::list<session_t> pendingDisconnect;
|
std::vector<session_t> pendingDisconnect;
|
||||||
std::map<session_t, bool> pending_unreliable;
|
std::map<session_t, bool> pending_unreliable;
|
||||||
|
|
||||||
const unsigned int peer_packet_quota = m_iteration_packets_avaialble
|
const unsigned int peer_packet_quota = m_iteration_packets_avaialble
|
||||||
@ -843,13 +843,11 @@ void *ConnectionReceiveThread::run()
|
|||||||
if (debug_print_timer > 20.0) {
|
if (debug_print_timer > 20.0) {
|
||||||
debug_print_timer -= 20.0;
|
debug_print_timer -= 20.0;
|
||||||
|
|
||||||
std::list<session_t> peerids = m_connection->getPeerIDs();
|
std::vector<session_t> peerids = m_connection->getPeerIDs();
|
||||||
|
|
||||||
for (std::list<session_t>::iterator i = peerids.begin();
|
for (auto id : peerids)
|
||||||
i != peerids.end();
|
|
||||||
i++)
|
|
||||||
{
|
{
|
||||||
PeerHelper peer = m_connection->getPeerNoEx(*i);
|
PeerHelper peer = m_connection->getPeerNoEx(id);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1039,7 +1037,7 @@ void ConnectionReceiveThread::receive(SharedBuffer<u8> &packetdata,
|
|||||||
|
|
||||||
bool ConnectionReceiveThread::getFromBuffers(session_t &peer_id, SharedBuffer<u8> &dst)
|
bool ConnectionReceiveThread::getFromBuffers(session_t &peer_id, SharedBuffer<u8> &dst)
|
||||||
{
|
{
|
||||||
std::list<session_t> peerids = m_connection->getPeerIDs();
|
std::vector<session_t> peerids = m_connection->getPeerIDs();
|
||||||
|
|
||||||
for (session_t peerid : peerids) {
|
for (session_t peerid : peerids) {
|
||||||
PeerHelper peer = m_connection->getPeerNoEx(peerid);
|
PeerHelper peer = m_connection->getPeerNoEx(peerid);
|
||||||
|
Loading…
Reference in New Issue
Block a user