示例#1
0
// Searching for free clients and connecting them
// Also removing inactive clients
void Server::timerEvent( QTimerEvent* event )
{
    Q_UNUSED( event );
    ClientsIterator freeClient = clients_.end();

    for( ClientsIterator cit = clients_.begin(); cit != clients_.end(); cit++ )
    {
        // Remove disconnected clients from list
        if( cit->status == Client::ST_DISCONNECTED )
        {
            if( freeClient == cit )
                freeClient = clients_.end();

            cit = clients_.erase( cit );
            continue;
        }

        if( cit->lastSeen() >= DEFAULT_INACTIVE_MIN )
            cit->socket->write( "ping:" );

        // Mark zombie clients as disconnected and record to the statistic
        if( cit->lastSeen() >= DEFAULT_INACTIVE_MAX )
        {
            disconnectClientAndRecord( cit, false );
            continue;
        }

        if( cit->status != Client::ST_READY )
            continue;

        if(
            freeClient != clients_.end() &&
            freeClient != cit &&
            freeClient->status == Client::ST_READY
        )
        {
            connectTwoClients( freeClient, cit );
            freeClient = clients_.end();
            continue;
        }

        freeClient = cit;
    }
}
示例#2
0
void MainServer::onTimer()
{
    // Searching for free clients and connecting them
    Clients::iterator freeClient = clients.end();

    for( Clients::iterator i = clients.begin(); i != clients.end(); i++ )
    {
        if( i->status == ST_READY )
        {
            if( freeClient == clients.end() )
                freeClient = i;
            else
            {
                connectTwoClients( freeClient, i );
                freeClient = clients.end();
            }
        }
    }
}