void CListenSocket::UpdateConnectionsStatus() { activeconnections = GetOpenSockets(); // Update statistics for 'peak connections' if (peakconnections < activeconnections) peakconnections = activeconnections; if (peakconnections > thePrefs.GetConnPeakConnections()) thePrefs.SetConnPeakConnections(peakconnections); // Comment UI if (CGlobalVariable::IsConnected()) { totalconnectionchecks++; if (totalconnectionchecks == 0) { // wrap around occured, avoid division by zero totalconnectionchecks = 100; } // Get a weight for the 'avg. connections' value. The longer we run the higher // gets the weight (the percent of 'avg. connections' we use). float fPercent = (float)(totalconnectionchecks - 1) / (float)totalconnectionchecks; if (fPercent > 0.99F) fPercent = 0.99F; // The longer we run the more we use the 'avg. connections' value and the less we // use the 'active connections' value. However, if we are running quite some time // without any connections (except the server connection) we will eventually create // a floating point underflow exception. averageconnections = averageconnections * fPercent + activeconnections * (1.0F - fPercent); if (averageconnections < 0.001F) averageconnections = 0.001F; // avoid floating point underflow } }
void CListenSocket::Process() { m_OpenSocketsInterval = 0; POSITION pos2; for (POSITION pos1 = socket_list.GetHeadPosition(); (pos2 = pos1) != NULL; ) { socket_list.GetNext(pos1); CClientReqSocket* cur_sock = socket_list.GetAt(pos2); if (cur_sock->IsDeleteThis()) { if (cur_sock->IsValidSocket()){ cur_sock->Close(); // calls 'closesocket' } else{ cur_sock->Delete_Timed(); // may delete 'cur_sock' } } else{ cur_sock->CheckTimeOut(); // may call 'shutdown' } } if ((GetOpenSockets() + 5 < thePrefs.GetMaxConnections() || CGlobalVariable::serverconnect->IsConnecting()) && !bListening) ReStartListening(); }
bool CListenSocket::TooManySockets(bool bIgnoreInterval) { if (GetOpenSockets() > thePrefs::GetMaxConnections() || (m_OpenSocketsInterval > (thePrefs::GetMaxConperFive()*GetMaxConperFiveModifier()) && !bIgnoreInterval)) { return true; } else { return false; } }
void CListenSocket::UpdateConnectionsStatus() { // 0.42e xcept for the khaos stats if( theApp->IsConnected() ) { totalconnectionchecks++; float percent; percent = (float)(totalconnectionchecks-1)/(float)totalconnectionchecks; if( percent > .99f ) { percent = .99f; } averageconnections = (averageconnections*percent) + (float)GetOpenSockets()*(1.0f-percent); } }
float CListenSocket::GetMaxConperFiveModifier() { float SpikeSize = GetOpenSockets() - averageconnections; if (SpikeSize < 1.0F) return 1.0F; float SpikeTolerance = 25.0F * (float)thePrefs.GetMaxConperFive() / 10.0F; if (SpikeSize > SpikeTolerance) return 0; float Modifier = 1.0F - SpikeSize / SpikeTolerance; return Modifier; }
float CListenSocket::GetMaxConperFiveModifier() { float SpikeSize = GetOpenSockets() - averageconnections; if ( SpikeSize < 1 ) { return 1; } float SpikeTolerance = 2.5f*thePrefs::GetMaxConperFive(); if ( SpikeSize > SpikeTolerance ) { return 0; } return 1.0f - (SpikeSize/SpikeTolerance); }
bool CListenSocket::TooManySockets( bool bIgnoreInterval, bool bUseTcp/*=false*/, bool bUseNat/*=false*/ ) { if ( GetOpenSockets() > thePrefs.GetMaxConnections() || (m_OpenSocketsInterval > (thePrefs.GetMaxConperFive() * GetMaxConperFiveModifier()) && !bIgnoreInterval) ) return true; if( bUseTcp && m_nHalfOpen >= thePrefs.GetMaxHalfConnections() && !bIgnoreInterval ) return true; if( bUseNat && m_nHalfOpenOfL2L >= thePrefs.GetMaxL2LHalfConnections() && !bIgnoreInterval ) return true; return false; }
void CListenSocket::Process() { // 042e + Kry changes for Destroy m_OpenSocketsInterval = 0; SocketSet::iterator it = socket_list.begin(); while ( it != socket_list.end() ) { CClientTCPSocket* cur_socket = *it++; if (!cur_socket->OnDestroy()) { if (cur_socket->ForDeletion()) { cur_socket->Destroy(); } else { cur_socket->CheckTimeOut(); } } } if ((GetOpenSockets()+5 < thePrefs::GetMaxConnections() || theApp->serverconnect->IsConnecting()) && !bListening) { ReStartListening(); } }