当前位置: 首页>>代码示例>>C++>>正文


C++ Connections::size方法代码示例

本文整理汇总了C++中Connections::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Connections::size方法的具体用法?C++ Connections::size怎么用?C++ Connections::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connections的用法示例。


在下文中一共展示了Connections::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: windowLocker

void P2PConnectionsWindow::refreshConnections()
{
	Connections connections;
	// Effettua una copia per evitare una lock durante il check
	getConnections(connections);

	wxWindowUpdateLocker windowLocker(m_connectionsCtrl);

	uint32 connectionsCount = static_cast<uint32>(connections.size());
	uint32 connectionsLimit = getConnectionsLimit();

	bool pendingRefresh = false;

	for(Connections::iterator i = connections.begin(); i != connections.end(); ++i)
	{
		if(i->second->getRemoved())
		{
			if(i->second->isElapsed() || (connectionsCount > connectionsLimit))
			{
				doRemoveConnection(i->first);
				connectionsCount--;
			}
			else
			{
				markConnectionRemoved(i->first);
			}
		}
		else
		{
			refreshConnectionItem(i->first);
		}
	}
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: GetConnection

NNTPConnection* ServerPool::GetConnection(int iLevel, NewsServer* pWantServer, Servers* pIgnoreServers)
{
	PooledConnection* pConnection = NULL;
	m_mutexConnections.Lock();

	time_t tCurTime = time(NULL);

	if (iLevel < (int)m_Levels.size() && m_Levels[iLevel] > 0)
	{
		Connections candidates;
		candidates.reserve(m_Connections.size());

		for (Connections::iterator it = m_Connections.begin(); it != m_Connections.end(); it++)
		{
			PooledConnection* pCandidateConnection = *it;
			NewsServer* pCandidateServer = pCandidateConnection->GetNewsServer();
			if (!pCandidateConnection->GetInUse() && pCandidateServer->GetActive() &&
				pCandidateServer->GetNormLevel() == iLevel && 
				(!pWantServer || pCandidateServer == pWantServer ||
				 (pWantServer->GetGroup() > 0 && pWantServer->GetGroup() == pCandidateServer->GetGroup())) &&
				(pCandidateConnection->GetStatus() == Connection::csConnected ||
				 !pCandidateServer->GetBlockTime() ||
				 pCandidateServer->GetBlockTime() + m_iRetryInterval <= tCurTime ||
				 pCandidateServer->GetBlockTime() > tCurTime))
			{
				// free connection found, check if it's not from the server which should be ignored
				bool bUseConnection = true;
				if (pIgnoreServers && !pWantServer)
				{
					for (Servers::iterator it = pIgnoreServers->begin(); it != pIgnoreServers->end(); it++)
					{
						NewsServer* pIgnoreServer = *it;
						if (pIgnoreServer == pCandidateServer ||
							(pIgnoreServer->GetGroup() > 0 && pIgnoreServer->GetGroup() == pCandidateServer->GetGroup() &&
							 pIgnoreServer->GetNormLevel() == pCandidateServer->GetNormLevel()))
						{
							bUseConnection = false;
							break;
						}
					}
				}

				pCandidateServer->SetBlockTime(0);

				if (bUseConnection)
				{
					candidates.push_back(pCandidateConnection);
				}
			}
		}

		if (!candidates.empty())
		{
			// Peeking a random free connection. This is better than taking the first
			// available connection because provides better distribution across news servers,
			// especially when one of servers becomes unavailable or doesn't have requested articles.
			int iRandomIndex = rand() % candidates.size();
			pConnection = candidates[iRandomIndex];
			pConnection->SetInUse(true);
		}

		if (pConnection)
		{
			m_Levels[iLevel]--;
		}
	}

	m_mutexConnections.Unlock();

	return pConnection;
}
开发者ID:0BruceWayne0,项目名称:nzbget,代码行数:71,代码来源:ServerPool.cpp


注:本文中的Connections::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。