connection->IsBusy(isBusy, isInboxConnection);
rv = connection->IsBusy(isBusy, isInboxConnection); if (NS_FAILED(rv)) continue;
nsImapIncomingServer::CreateImapConnection(nsIEventQueue *aEventQueue,                                            nsIImapUrl * aImapUrl,                                            nsIImapProtocol ** aImapConnection){	nsresult rv = NS_OK;	PRBool canRunUrl = PR_FALSE;    PRBool hasToWait = PR_FALSE;	nsCOMPtr<nsIImapProtocol> connection;    nsCOMPtr<nsIImapProtocol> freeConnection;    PRBool isBusy = PR_FALSE;    PRBool isInboxConnection = PR_FALSE;    PR_CEnterMonitor(this);    PRInt32 maxConnections = 5; // default to be five    rv = GetMaximumConnectionsNumber(&maxConnections);    if (NS_FAILED(rv) || maxConnections == 0)    {        maxConnections = 5;        rv = SetMaximumConnectionsNumber(maxConnections);    }    else if (maxConnections < 2)    {   // forced to use at least 2        maxConnections = 2;        rv = SetMaximumConnectionsNumber(maxConnections);    }    *aImapConnection = nsnull;	// iterate through the connection cache for a connection that can handle this url.	PRUint32 cnt;    rv = m_connectionCache->Count(&cnt);    if (NS_FAILED(rv)) return rv;    for (PRUint32 i = 0; i < cnt && !canRunUrl && !hasToWait; i++) 	{        connection = do_QueryInterface(m_connectionCache->ElementAt(i));		if (connection)			connection->CanHandleUrl(aImapUrl, canRunUrl, hasToWait);                if (!freeConnection && !canRunUrl && !hasToWait && connection)        {            connection->IsBusy(isBusy, isInboxConnection);            if (!isBusy && !isInboxConnection)                freeConnection = connection;        }	}	// if we got here and we have a connection, then we should return it!	if (canRunUrl && connection)	{		*aImapConnection = connection;		NS_IF_ADDREF(*aImapConnection);	}    else if (hasToWait)    {        // do nothing; return NS_OK; for queuing    }	else if (cnt < maxConnections && aEventQueue)	{			// create a new connection and add it to the connection cache		// we may need to flag the protocol connection as busy so we don't get        // a race 		// condition where someone else goes through this code 		nsIImapProtocol * protocolInstance = nsnull;		rv = nsComponentManager::CreateInstance(kImapProtocolCID, nsnull,                                                nsIImapProtocol::GetIID(),                                                (void **) &protocolInstance);		if (NS_SUCCEEDED(rv) && protocolInstance)        {            NS_WITH_SERVICE(nsIImapHostSessionList, hostSession,                            kCImapHostSessionList, &rv);            if (NS_SUCCEEDED(rv))                rv = protocolInstance->Initialize(hostSession, aEventQueue);        }				// take the protocol instance and add it to the connectionCache		if (protocolInstance)			m_connectionCache->AppendElement(protocolInstance);		*aImapConnection = protocolInstance; // this is already ref counted.	}    else if (freeConnection)    {        *aImapConnection = freeConnection;        NS_IF_ADDREF(*aImapConnection);    }    else // cannot get anyone to handle the url queue it    {        // queue the url    }    PR_CExitMonitor(this);	return rv;}