#include "StdAfx.h"
#include "BandWidthControl.h"

CBandWidthControl::CBandWidthControl(void)
{
	m_startTick = GetTickCount();
}


/*!
	待機を実行
*/
void CBandWidthControl::BandWidthWait(int limit, int transSize, HANDLE breakEvent)
{
	//	制限なし？
	if(limit < 0)
		return;

	//	時刻取得
	DWORD	curTime = GetTickCount();
	if(curTime < m_startTick)
		return;

	//	経過時刻取得
	int	transTime = GetTickCount() - m_startTick;

	//	終了時刻計算
	int	waitTime = (int)(((double)transSize / (double)limit) * 1000.0);
	if(waitTime <= transTime)
		return;

	TRACE("Wait : %d\n", waitTime - transTime);

	//	待機
	::WaitForSingleObject(breakEvent, waitTime - transTime);
}

