Skip to content

Commit

Permalink
Merge pull request #2151 from softins/channel-allocation
Browse files Browse the repository at this point in the history
Keep the list of free channels in sorted order
  • Loading branch information
softins authored Dec 11, 2021
2 parents ccdb3dd + 7bc861b commit 081cce4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ int CServer::FindChannel ( const CHostAddress& CheckAddr, const bool bAllowNew )
return vecChannelOrder[t];
}

if ( cmp < 0 )
if ( cmp > 0 )
{
l = t + 1;
}
Expand Down Expand Up @@ -1574,13 +1574,14 @@ void CServer::FreeChannel ( const int iCurChanID )
{
--iCurNumChannels;

// move channel IDs down by one starting at the bottom and working up
while ( i < iCurNumChannels )
// move channel IDs down by one starting at the freed channel and working up the active channels
// and then the free channels until its position in the free list is reached
while ( i < iCurNumChannels || ( i + 1 < iMaxNumChannels && vecChannelOrder[i + 1] < iCurChanID ) )
{
int j = i++;
vecChannelOrder[j] = vecChannelOrder[i];
}
// put deleted channel at the end ready for re-use
// put deleted channel in the vacated position ready for re-use
vecChannelOrder[i] = iCurChanID;

// DumpChannels ( __FUNCTION__ );
Expand Down

0 comments on commit 081cce4

Please sign in to comment.