Add GetActiveConnectionCount to IConnectionSet
This commit is contained in:
@@ -47,5 +47,9 @@ namespace AzNetworking
|
||||
//! Returns the current total connection count for this connection set
|
||||
//! @return the current total connection count for this connection set
|
||||
virtual uint32_t GetConnectionCount() const = 0;
|
||||
|
||||
//! Returns the current total count of connections not pending disconnect for this connection set
|
||||
//! @return the current total count of connections not pending disconnect for this connection set
|
||||
virtual uint32_t GetActiveConnectionCount() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,6 +114,24 @@ namespace AzNetworking
|
||||
return aznumeric_cast<uint32_t>(m_connectionIdMap.size());
|
||||
}
|
||||
|
||||
uint32_t TcpConnectionSet::GetActiveConnectionCount() const
|
||||
{
|
||||
uint32_t activeConnections = 0;
|
||||
for (auto iter = m_connectionIdMap.begin(); iter != m_connectionIdMap.end(); ++iter)
|
||||
{
|
||||
if (iter->second.get())
|
||||
{
|
||||
ConnectionState state = iter->second.get()->GetConnectionState();
|
||||
if (state == ConnectionState::Connected || state == ConnectionState::Connecting)
|
||||
{
|
||||
++activeConnections;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return activeConnections;
|
||||
}
|
||||
|
||||
TcpConnection* TcpConnectionSet::GetConnection(SocketFd socketFd) const
|
||||
{
|
||||
SocketFdMap::const_iterator lookup = m_socketFdMap.find(socketFd);
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace AzNetworking
|
||||
IConnection* GetConnection(ConnectionId connectionId) const override;
|
||||
ConnectionId GetNextConnectionId() override;
|
||||
uint32_t GetConnectionCount() const override;
|
||||
uint32_t GetActiveConnectionCount() const override;
|
||||
//! @}
|
||||
|
||||
//! Retrieves a connection from this connection list instance by socket fd.
|
||||
|
||||
@@ -111,6 +111,24 @@ namespace AzNetworking
|
||||
return aznumeric_cast<uint32_t>(m_connectionIdMap.size());
|
||||
}
|
||||
|
||||
uint32_t UdpConnectionSet::GetActiveConnectionCount() const
|
||||
{
|
||||
uint32_t activeConnections = 0;
|
||||
for (auto iter = m_connectionIdMap.begin(); iter != m_connectionIdMap.end(); ++iter)
|
||||
{
|
||||
if (iter->second.get())
|
||||
{
|
||||
ConnectionState state = iter->second.get()->GetConnectionState();
|
||||
if (state == ConnectionState::Connected || state == ConnectionState::Connecting)
|
||||
{
|
||||
++activeConnections;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return activeConnections;
|
||||
}
|
||||
|
||||
UdpConnection* UdpConnectionSet::GetConnection(const IpAddress& address) const
|
||||
{
|
||||
RemoteAddressMap::const_iterator lookup = m_remoteAddressMap.find(address);
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace AzNetworking
|
||||
IConnection* GetConnection(ConnectionId connectionId) const override;
|
||||
ConnectionId GetNextConnectionId() override;
|
||||
uint32_t GetConnectionCount() const override;
|
||||
uint32_t GetActiveConnectionCount() const override;
|
||||
//! @}
|
||||
|
||||
//! Retrieves a connection from this connection list instance by endpoint remote address
|
||||
|
||||
@@ -700,7 +700,7 @@ namespace Multiplayer
|
||||
// We avoid this for client server as the host itself is a user and non-transient dedicated servers
|
||||
if (sv_isTransient && m_agentType == MultiplayerAgentType::DedicatedServer && connection->GetConnectionRole() == ConnectionRole::Acceptor)
|
||||
{
|
||||
if (m_networkInterface->GetConnectionSet().GetConnectionCount() == 0)
|
||||
if (m_networkInterface->GetConnectionSet().GetActiveConnectionCount() == 0)
|
||||
{
|
||||
Terminate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user