CClients::m_Clients is a list

pull/1/head
Tom Early 6 years ago
parent b7a77491a4
commit 811e950e91

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -33,7 +34,6 @@
CClients::CClients()
{
m_Clients.reserve(100);
}
////////////////////////////////////////////////////////////////////////////////////////
@ -42,14 +42,11 @@ CClients::CClients()
CClients::~CClients()
{
m_Mutex.lock();
for ( auto it=begin(); it!=end(); it++ )
{
for ( int i = 0; i < m_Clients.size(); i++ )
{
delete m_Clients[i];
delete *it;
}
m_Clients.clear();
}
m_Mutex.unlock();
}
@ -59,29 +56,19 @@ CClients::~CClients()
void CClients::AddClient(CClient *client)
{
// first check if client already exists
bool found = false;
for ( int i = 0; (i < m_Clients.size()) && !found; i++ )
for ( auto it=begin(); it!=end(); it++ )
{
found = (*client == *m_Clients[i]);
if (*client == *(*it))
// if found, just do nothing
// so *client keep pointing on a valid object
// on function return
if ( found )
{
// delete new one
delete client;
//std::cout << "Adding existing client " << client->GetCallsign() << " at " << client->GetIp() << std::endl;
return;
}
}
// if not, append to the vector
if ( !found )
{
// grow vector capacity if needed
if ( m_Clients.capacity() == m_Clients.size() )
{
m_Clients.reserve(m_Clients.capacity()+10);
}
// and append
m_Clients.push_back(client);
std::cout << "New client " << client->GetCallsign() << " at " << client->GetIp()
@ -94,58 +81,44 @@ void CClients::AddClient(CClient *client)
// notify
g_Reflector.OnClientsChanged();
}
}
void CClients::RemoveClient(CClient *client)
{
// look for the client
bool found = false;
for ( int i = 0; (i < m_Clients.size()) && !found; i++ )
for ( auto it=begin(); it!=end(); it++ )
{
// compare objetc pointers
if ( (m_Clients[i]) == client )
if ( *it == client )
{
// found it !
if ( !m_Clients[i]->IsAMaster() )
if ( !(*it)->IsAMaster() )
{
// remove it
std::cout << "Client " << m_Clients[i]->GetCallsign() << " at " << m_Clients[i]->GetIp()
<< " removed with protocol " << client->GetProtocolName();
if ( client->GetReflectorModule() != ' ' )
std::cout << "Client " << (*it)->GetCallsign() << " at " << (*it)->GetIp() << " removed with protocol " << (*it)->GetProtocolName();
if ( (*it)->GetReflectorModule() != ' ' )
{
std::cout << " on module " << client->GetReflectorModule();
std::cout << " on module " << (*it)->GetReflectorModule();
}
std::cout << std::endl;
delete m_Clients[i];
m_Clients.erase(m_Clients.begin()+i);
found = true;
delete *it;
m_Clients.erase(it);
// notify
g_Reflector.OnClientsChanged();
break;
}
}
}
}
CClient *CClients::GetClient(int i)
{
if ( (i >= 0) && (i < m_Clients.size()) )
{
return m_Clients[i];
}
else
{
return NULL;
}
}
bool CClients::IsClient(CClient *client) const
{
bool found = false;
for ( int i = 0; (i < m_Clients.size()) && !found; i++ )
for ( auto it=cbegin(); it!=cend(); it++ )
{
found = (m_Clients[i] == client);
if (*it == client)
return true;
}
return found;
return false;
}
////////////////////////////////////////////////////////////////////////////////////////
@ -153,171 +126,140 @@ bool CClients::IsClient(CClient *client) const
CClient *CClients::FindClient(const CIp &Ip)
{
CClient *client = NULL;
// find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
for ( auto it=begin(); it!=end(); it++ )
{
if ( m_Clients[i]->GetIp() == Ip )
if ( (*it)->GetIp() == Ip )
{
client = m_Clients[i];
return *it;
}
}
// done
return client;
return NULL;
}
CClient *CClients::FindClient(const CIp &Ip, int Protocol)
{
CClient *client = NULL;
// find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
for ( auto it=begin(); it!=end(); it++ )
{
if ( (m_Clients[i]->GetIp() == Ip) && (m_Clients[i]->GetProtocol() == Protocol))
if ( ((*it)->GetIp() == Ip) && ((*it)->GetProtocol() == Protocol))
{
client = m_Clients[i];
return *it;
}
}
// done
return client;
return NULL;
}
CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule)
{
CClient *client = NULL;
// find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
for ( auto it=begin(); it!=end(); it++ )
{
if ( (m_Clients[i]->GetIp() == Ip) &&
(m_Clients[i]->GetReflectorModule() == ReflectorModule) &&
(m_Clients[i]->GetProtocol() == Protocol) )
if ( ((*it)->GetIp() == Ip) &&
((*it)->GetReflectorModule() == ReflectorModule) &&
((*it)->GetProtocol() == Protocol) )
{
client = m_Clients[i];
return *it;
}
}
// done
return client;
return NULL;
}
CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol)
{
CClient *client = NULL;
// find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
for ( auto it=begin(); it!=end(); it++ )
{
if ( m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) &&
(m_Clients[i]->GetIp() == Ip) &&
(m_Clients[i]->GetProtocol() == Protocol) )
if ( (*it)->GetCallsign().HasSameCallsign(Callsign) &&
((*it)->GetIp() == Ip) &&
((*it)->GetProtocol() == Protocol) )
{
client = m_Clients[i];
return *it;
}
}
// done
return client;
return NULL;
}
CClient *CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol)
{
CClient *client = NULL;
// find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
for ( auto it=begin(); it!=end(); it++ )
{
if ( m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) &&
(m_Clients[i]->GetModule() == module) &&
(m_Clients[i]->GetIp() == Ip) &&
(m_Clients[i]->GetProtocol() == Protocol) )
if ( (*it)->GetCallsign().HasSameCallsign(Callsign) &&
((*it)->GetModule() == module) &&
((*it)->GetIp() == Ip) &&
((*it)->GetProtocol() == Protocol) )
{
client = m_Clients[i];
return *it;
}
}
// done
return client;
return NULL;
}
CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol)
{
CClient *client = NULL;
// find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
for ( auto it=begin(); it!=end(); it++ )
{
if ( (m_Clients[i]->GetProtocol() == Protocol) &&
m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) )
if ( ((*it)->GetProtocol() == Protocol) &&
(*it)->GetCallsign().HasSameCallsign(Callsign) )
{
client = m_Clients[i];
return *it;
}
}
// done
return client;
return NULL;
}
////////////////////////////////////////////////////////////////////////////////////////
// iterate on clients
CClient *CClients::FindNextClient(int Protocol, int *index)
CClient *CClients::FindNextClient(int Protocol, std::list<CClient *>::iterator &it)
{
CClient *client = NULL;
// find next client
bool found = false;
for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ )
while ( it != end() )
{
if ( m_Clients[i]->GetProtocol() == Protocol )
if ( (*it)->GetProtocol() == Protocol )
{
found = true;
client = m_Clients[i];
*index = i;
return *it++;
}
it++;
}
return client;
return NULL;
}
CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, int *index)
CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, std::list<CClient *>::iterator &it)
{
CClient *client = NULL;
// find next client
bool found = false;
for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ )
while ( it != end() )
{
if ( (m_Clients[i]->GetProtocol() == Protocol) &&
(m_Clients[i]->GetIp() == Ip) )
if ( ((*it)->GetProtocol() == Protocol) &&
((*it)->GetIp() == Ip) )
{
found = true;
client = m_Clients[i];
*index = i;
return *it++;
}
it++;
}
return client;
return NULL;
}
CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, int *index)
CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, std::list<CClient *>::iterator &it)
{
CClient *client = NULL;
// find next client
bool found = false;
for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ )
while ( it != end() )
{
if ( (m_Clients[i]->GetProtocol() == Protocol) &&
(m_Clients[i]->GetIp() == Ip) &&
m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) )
if ( ((*it)->GetProtocol() == Protocol) &&
((*it)->GetIp() == Ip) &&
(*it)->GetCallsign().HasSameCallsign(Callsign) )
{
found = true;
client = m_Clients[i];
*index = i;
return *it++;
}
it++;
}
return client;
return NULL;
}

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -52,9 +53,14 @@ public:
int GetSize(void) const { return (int)m_Clients.size(); }
void AddClient(CClient *);
void RemoveClient(CClient *);
CClient *GetClient(int);
bool IsClient(CClient *) const;
// pass-thru
std::list<CClient *>::iterator begin() { return m_Clients.begin(); }
std::list<CClient *>::iterator end() { return m_Clients.end(); }
std::list<CClient *>::const_iterator cbegin() const { return m_Clients.cbegin(); }
std::list<CClient *>::const_iterator cend() const { return m_Clients.cend(); }
// find clients
CClient *FindClient(const CIp &);
CClient *FindClient(const CIp &, int);
@ -64,14 +70,14 @@ public:
CClient *FindClient(const CCallsign &, int);
// iterate on clients
CClient *FindNextClient(int, int*);
CClient *FindNextClient(const CIp &, int, int *);
CClient *FindNextClient(const CCallsign &, const CIp &, int, int *);
CClient *FindNextClient(int, std::list<CClient *>::iterator &);
CClient *FindNextClient(const CIp &, int, std::list<CClient *>::iterator &);
CClient *FindNextClient(const CCallsign &, const CIp &, int, std::list<CClient *>::iterator &);
protected:
// data
std::mutex m_Mutex;
std::vector<CClient *> m_Clients;
std::list<CClient *> m_Clients;
};

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 07/11/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -162,9 +163,9 @@ void CDcsProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, &index)) != NULL )
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != NULL )
{
client->Alive();
}
@ -301,9 +302,9 @@ void CDcsProtocol::HandleQueue(void)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DCS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -336,9 +337,9 @@ void CDcsProtocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DCS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL )
{
// encode client's specific keepalive packet
CBuffer keepalive2;

@ -200,9 +200,9 @@ void CDextraProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, &index)) != NULL )
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != NULL )
{
client->Alive();
}
@ -260,9 +260,9 @@ void CDextraProtocol::HandleQueue(void)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -298,9 +298,9 @@ void CDextraProtocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL )
{
// send keepalive
m_Socket.Send(keepalive, client->GetIp());
@ -339,7 +339,7 @@ void CDextraProtocol::HandleKeepalives(void)
// iterate on peers
CPeers *peers = g_Reflector.GetPeers();
index = -1;
int index = -1;
CPeer *peer = NULL;
while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, &index)) != NULL )
{

@ -217,9 +217,9 @@ void CDmrmmdvmProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, &index)) != NULL )
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != NULL )
{
// acknowledge
EncodeKeepAlivePacket(&Buffer, client);
@ -441,9 +441,9 @@ void CDmrmmdvmProtocol::HandleQueue(void)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -473,9 +473,9 @@ void CDmrmmdvmProtocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL )
{
// is this client busy ?
if ( client->IsAMaster() )

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 10/01/2016.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -315,9 +316,9 @@ void CDmrplusProtocol::HandleQueue(void)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -344,9 +345,9 @@ void CDmrplusProtocol::SendBufferToClients(const CBuffer &buffer, uint8 module)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == module) )
@ -374,9 +375,9 @@ void CDmrplusProtocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL )
{
// is this client busy ?
if ( client->IsAMaster() )

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 01/11/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -160,9 +161,9 @@ void CDplusProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, &index)) != NULL )
while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != NULL )
{
client->Alive();
}
@ -294,9 +295,9 @@ void CDplusProtocol::HandleQueue(void)
// note that for dplus protocol, all stream of all modules are push to all clients
// it's client who decide which stream he's interrrested in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() )
@ -388,9 +389,9 @@ void CDplusProtocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL )
{
// send keepalive
//std::cout << "Sending DPlus packet @ " << client->GetIp() << std::endl;

@ -4,6 +4,7 @@
//
// Created by Marius Petrescu (YO2LOJ) on 03/06/2019.
// Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -183,10 +184,9 @@ void CG3Protocol::PresenceTask(void)
}
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *extant = NULL;
while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
CIp ClIp = extant->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr())
@ -197,10 +197,10 @@ void CG3Protocol::PresenceTask(void)
if (extant == NULL)
{
index = -1;
it = clients->begin();
// do we already have a client with the same call (IP changed)?
while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
{
if (extant->GetCallsign().HasSameCallsign(Terminal))
@ -359,10 +359,9 @@ void CG3Protocol::IcmpTask(void)
if (iIcmpType == ICMP_DEST_UNREACH)
{
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
CIp ClientIp = client->GetIp();
if (ClientIp.GetAddr() == Ip.GetAddr())
@ -396,9 +395,9 @@ void CG3Protocol::Task(void)
CIp ClIp;
CIp *BaseIp = NULL;
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
ClIp = client->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr())
@ -498,9 +497,9 @@ void CG3Protocol::HandleQueue(void)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -534,9 +533,9 @@ void CG3Protocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
if (!client->IsAlive())
{
@ -568,10 +567,9 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find this client
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
CIp ClIp = client->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr())
@ -785,9 +783,9 @@ void CG3Protocol::NeedReload(void)
// we have new options - iterate on clients for potential removal
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{
char module = client->GetReflectorModule();
if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*'))
@ -858,4 +856,3 @@ void CG3Protocol::ReadOptions(void)
}
}
}

@ -630,11 +630,11 @@ void CReflector::WriteXmlFile(std::ofstream &xmlFile)
// lock
CClients *clients = GetClients();
// iterate on clients
for ( int i = 0; i < clients->GetSize(); i++ )
for ( auto it=clients->cbegin(); it!=clients->cend(); it++ )
{
if ( clients->GetClient(i)->IsNode() )
if ( (*it)->IsNode() )
{
clients->GetClient(i)->WriteXml(xmlFile);
(*it)->WriteXml(xmlFile);
}
}
// unlock
@ -696,10 +696,10 @@ void CReflector::SendJsonNodesObject(CUdpSocket &Socket, CIp &Ip)
// lock
CClients *clients = GetClients();
// iterate on clients
for ( int i = 0; (i < clients->GetSize()) && (i < JSON_NBMAX_NODES); i++ )
for ( auto it=clients->cbegin(); it!=clients->cend(); )
{
clients->GetClient(i)->GetJsonObject(Buffer);
if ( i < clients->GetSize()-1 )
(*it++)->GetJsonObject(Buffer);
if ( it != clients->cend() )
{
::strcat(Buffer, ",");
}

@ -271,9 +271,9 @@ void CXlxProtocol::HandleQueue(void)
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_XLX, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 20/05/2018.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -350,9 +351,9 @@ void CYsfProtocol::HandleQueue(void)
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_YSF, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -382,9 +383,9 @@ void CYsfProtocol::HandleKeepalives(void)
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
auto it = clients->begin();
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_YSF, &index)) != NULL )
while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL )
{
// is this client busy ?
if ( client->IsAMaster() )

Loading…
Cancel
Save

Powered by TurnKey Linux.