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


C++ Timer::Begin方法代码示例

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


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

示例1: SendThread

void TestClient::SendThread()
{
	vector<ClientData*> clientList;
	UINT halfTick = m_InitData.Timeout >> 1;
	NetCmd nc;
	nc.SetCmdSize(sizeof(nc));
	nc.SetCmdType(ConvertDWORDToWORD(m_InitData.CmdHearbeat));
	long threadIdx = ::InterlockedIncrement(&m_SendIndex) - 1;
	SafeList<ClientData*> &sendList = m_NewSendList[threadIdx];
	Timer t;
	t.Begin();
	while (m_bRun)
	{
		while (sendList.HasItem())
			clientList.push_back(sendList.GetItem());
		
		UINT tick = GetTickCount();
		for (UINT i = 0; i < clientList.size();)
		{
			ClientData *pc = clientList[i];
			if (pc->InsideRemoved)
			{
				RemoveClient(pc);
				ListRemoveAt(clientList, i);
				continue;
			}
			if (tick - pc->SendTick > halfTick)
			{
				int nret = send(pc->Socket, (const char*)&nc, nc.CmdSize, 0);
				if (nret != nc.CmdSize)
				{
					Log(L"send hearbeat err:%d, lastErr:%d", nret, WSAGetLastError());
				}
				pc->SendTick = tick;
			}
			++i;
		}
		m_SendData[threadIdx].Num = clientList.size();
		m_SendData[threadIdx].Delta = t.Intecept();
		Sleep(m_InitData.SleepTime);
	}
	for (UINT i = 0; i < clientList.size(); ++i)
		RemoveClient(clientList[i]);
	::InterlockedIncrement(&m_ExitCount);
}
开发者ID:kingstop,项目名称:HardwareProject,代码行数:45,代码来源:TestClient.cpp

示例2: RecvThread

void TestClient::RecvThread()
{
	fd_set  *pSet = CreateFDSet();
	timeval time = { 0, 0 };
	vector<ClientData*> recvList;
	long threadIdx = ::InterlockedIncrement(&m_RecvIndex) - 1;
	SafeList<ClientData*> &recvNewList = m_NewRecvList[threadIdx];
	Timer t;
	t.Begin();
	while (m_bRun)
	{
		while (recvNewList.HasItem())
		{
			recvList.push_back(recvNewList.GetItem());
		}
		FD_ZERO(pSet);
		UINT tick = GetTickCount();
		uint idx = 0;
		for (; idx < recvList.size();)
		{
			ClientData *pscd = recvList[idx];
			if (pscd->InsideRemoved || tick - pscd->RecvTick > m_InitData.Timeout)
			{
				if (tick - pscd->RecvTick > m_InitData.Timeout)
					Log(L"Timeout:%d", tick - pscd->RecvTick);
				RemoveClient(pscd);
				ListRemoveAt(recvList, idx);
				continue;
			}
			FD_ADD(pscd->Socket, pSet);
			++idx;
		}
		if (idx > 0)
		{
			int nRet = select(0, pSet, NULL, NULL, &time);
			if (nRet != 0)
			for (uint i = 0; i < recvList.size(); ++i)
			{
				ClientData *pscd = recvList[i];
				if (!FD_ISSET(pscd->Socket, pSet))
					continue;

				int curPos = pscd->Offset + pscd->RecvSize;
				nRet = recv(pscd->Socket, (char*)pscd->Buff + curPos, m_InitData.BuffSize - curPos, 0);
				if (nRet == 0 || (nRet == SOCKET_ERROR && (WSAGetLastError() == WSAECONNRESET || WSAGetLastError() == WSAECONNABORTED)))
				{
					Log(L"recv error:%d, LastCode:%d", nRet, WSAGetLastError());
					pscd->InsideRemoved = true;
				}
				else if (!RecvData(pscd, nRet))
				{
					Log(L"recv size error:%d, LastCode:%d", nRet, WSAGetLastError());
					pscd->InsideRemoved = true;
				}
				else
				{
					while (pscd->RecvList.HasItem())
					{
						free(pscd->RecvList.GetItem());
					}
					pscd->RecvTick = tick;
				}
			}// end for
		}//enf if

		m_RecvData[threadIdx].Num = recvList.size();
		m_RecvData[threadIdx].Delta = t.Intecept();
		Sleep(m_InitData.SleepTime);
	}
	for (UINT i = 0; i < recvList.size(); ++i)
		RemoveClient(recvList[i]);
	DeleteFDSet(pSet);
	::InterlockedIncrement(&m_ExitCount);
}
开发者ID:kingstop,项目名称:HardwareProject,代码行数:74,代码来源:TestClient.cpp


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