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


C++ CDownload::GetFirstTransfer方法代码示例

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


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

示例1: OnRun

void CDownloads::OnRun()
{
	DWORD nActiveDownloads		= 0;	// Number of downloads that are doing something
	DWORD nActiveTransfers		= 0;	// Number of transfers that are in the downloading state
	DWORD nTotalTransfers		= 0;	// Total transfers
	DWORD nTotalBandwidth		= 0;	// Total bandwidth in use
	DWORD nRunningTransfers		= 0;	// Number of transfers that are downloading and transfering data
	DWORD nRunningED2KTransfers	= 0;	// Number of ed2k transfers that are downloading and transfering data
	DWORD nTotalED2KBandwidth	= 0;	// Total ed2k bandwidth in use.

	{
		CTransfers::Lock oLock;

		m_nValidation = 0;
		++m_nRunCookie;
		
		for ( POSITION pos = GetIterator(); pos; )
		{
			CDownload* pDownload = GetNext( pos );
			pDownload->m_nRunCookie = m_nRunCookie;
			pDownload->OnRun();
			
			int nTemp = 0;
			
			for ( CDownloadTransfer* pTransfer = pDownload->GetFirstTransfer() ; pTransfer ; pTransfer = pTransfer->m_pDlNext )
			{
				if ( pTransfer->m_nProtocol == PROTOCOL_ED2K )
				{
					CDownloadTransferED2K* pED2K = (CDownloadTransferED2K*)pTransfer;
					if ( pED2K->m_pClient == NULL || pED2K->m_pClient->m_bConnected == FALSE ) continue;
					if ( pTransfer->m_nState == dtsQueued ) continue;
				}
				else if ( pTransfer->m_nProtocol == PROTOCOL_BT )
				{
					CDownloadTransferBT* pBT = (CDownloadTransferBT*)pTransfer;
					if ( pBT->m_nState == dtsTorrent && pBT->m_bChoked ) continue;
				}
				
				nTemp ++;
				
				if ( pTransfer->m_nState == dtsDownloading )
				{
					DWORD nSpeed = pTransfer->GetMeasuredSpeed();
					nTotalBandwidth += nSpeed;
					nActiveTransfers ++;
					if ( nSpeed > 32 ) nRunningTransfers ++; 

					if ( pTransfer->m_nProtocol == PROTOCOL_ED2K ) 
					{
						nTotalED2KBandwidth += nSpeed;
						if ( nSpeed > 32 ) nRunningED2KTransfers ++;
					}
				}
			}
			
			if ( nTemp )
			{
				nActiveDownloads ++;
				nTotalTransfers += nTemp;
			}
		}
	}

	m_nTransfers = nActiveTransfers;
	m_nBandwidth = nTotalBandwidth;
	
	m_bAllowMoreDownloads = nActiveDownloads < (DWORD)Settings.Downloads.MaxFiles;
	m_bAllowMoreTransfers = nTotalTransfers < (DWORD)Settings.Downloads.MaxTransfers;
	
	// Transfers that are not managing at least 32 bytes/sec are not counted when averaging limits
	if ( nRunningTransfers > 0 )
	{
		m_nLimitGeneric	= Settings.Bandwidth.Downloads / nRunningTransfers;
		m_nLimitDonkey = m_nLimitGeneric;
		if ( UploadQueues.IsDonkeyRatioActive() )
		{
			// Use either the minimum we have reserved, or the current upload allocation, whichever is greater.
			DWORD nDonkeyLimit = max( UploadQueues.GetMinimumDonkeyBandwidth(), UploadQueues.GetCurrentDonkeyBandwidth() );
		
			if ( nDonkeyLimit < 10240 )
			{
				// ED2K 3:1 ratio if you aren't uploading at 10KB/s
				nDonkeyLimit *= 3;	

				// Because this is a per-source limit, we should check overall usage as well.
				if ( nTotalED2KBandwidth > ( nDonkeyLimit / 2 ) )
				{
					// We're getting close to the ed2k ratio, so we need to limit some sources.

					if ( nRunningED2KTransfers > 0 )
						m_nLimitDonkey = nDonkeyLimit / nRunningED2KTransfers;
					else 
						m_nLimitDonkey = nDonkeyLimit;

				}

				// Make sure we have not set the ed2k limit higher than the general limit
				if ( m_nLimitGeneric ) m_nLimitDonkey = min( m_nLimitGeneric, m_nLimitDonkey );
			}
		}
//.........这里部分代码省略.........
开发者ID:ericfillipe1,项目名称:shareaza-code,代码行数:101,代码来源:Downloads.cpp

示例2: Update

void CHomeDownloadsBox::Update()
{
	if ( m_pDocument == NULL ) return;

	CSingleLock pLock( &Transfers.m_pSection );
	if ( ! pLock.Lock( 50 ) ) return;

	BOOL bChanged = FALSE;
	CString str;

	for ( INT_PTR nItem = m_pList.GetSize() - 1 ; nItem >= 0 ; nItem-- )
	{
		Item* pItem = m_pList.GetAt( nItem );

		if ( ! Downloads.CheckActive( pItem->m_pDownload, 6 ) )
		{
			delete pItem;
			m_pList.RemoveAt( nItem );
			bChanged = TRUE;
			m_pHover = NULL;
			KillTimer( 2 );
		}
	}

	int nCount = 0;
	int nInsert = 0;

	for ( POSITION pos = Downloads.GetReverseIterator() ; pos && nCount < 6 ; )
	{
		CDownload* pDownload = Downloads.GetPrevious( pos );
		if ( pDownload->IsPaused() ) continue;
		if ( pDownload->IsCompleted() ) continue;

		Item* pItem = NULL;

		for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
		{
			pItem = m_pList.GetAt( nItem );
			if ( pItem->m_pDownload == pDownload ) break;
			pItem = NULL;
		}

		if ( pItem == NULL )
		{
			pItem				= new Item();
			pItem->m_pDownload	= pDownload;
			pItem->m_sText		= pDownload->GetDisplayName();
			pItem->m_nIcon16	= ShellIcons.Get( pItem->m_sText, 16 );
			m_pList.InsertAt( nInsert++, pItem );
			bChanged = TRUE;
			m_pHover = NULL;
			KillTimer( 2 );
		}

		QWORD nComplete	= pDownload->GetVolumeComplete();
		BOOL bPaused	= pDownload->GetFirstTransfer() == NULL;

		if ( pItem->m_nComplete != nComplete ||
			 pItem->m_bPaused != bPaused ||
			 pItem->m_nSize != pDownload->m_nSize )
		{
			pItem->m_nSize		= pDownload->m_nSize;
			pItem->m_nComplete	= nComplete;
			pItem->m_bPaused	= bPaused;
			bChanged = TRUE;
		}

		nCount++;
	}

	nCount = static_cast< int >( m_pList.GetSize() * 18 );
	if ( nCount ) nCount += 6;

	m_pDocument->ShowGroup( 1, m_pList.GetSize() == 0 );

	int nActive = (int)CGraphItem::GetValue( GRC_DOWNLOADS_FILES );

	if ( nActive > 1 )
	{
		if ( m_pdDownloadsMany )
		{
			str.Format( m_sDownloadsMany, nActive );
			m_pdDownloadsMany->SetText( str );
			m_pdDownloadsMany->Show( TRUE );
		}
		if ( m_pdDownloadsOne )  m_pdDownloadsOne->Show( FALSE );
		if ( m_pdDownloadsNone ) m_pdDownloadsNone->Show( FALSE );
	}
	else if ( nActive == 1 )
	{
		if ( m_pdDownloadsMany ) m_pdDownloadsMany->Show( FALSE );
		if ( m_pdDownloadsOne )  m_pdDownloadsOne->Show( TRUE );
		if ( m_pdDownloadsNone ) m_pdDownloadsNone->Show( FALSE );
	}
	else
	{
		if ( m_pdDownloadsMany ) m_pdDownloadsMany->Show( FALSE );
		if ( m_pdDownloadsOne )  m_pdDownloadsOne->Show( FALSE );
		if ( m_pdDownloadsNone ) m_pdDownloadsNone->Show( TRUE );
	}
//.........这里部分代码省略.........
开发者ID:lemonxiao0,项目名称:peerproject,代码行数:101,代码来源:CtrlHomePanel.cpp


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