Esempio n. 1
0
void RNS2_NativeClient::ProcessBufferedSend(void)
{
	// Don't send until bound
	if (bindState!=BS_BOUND)
		return;
	// Fast non-threadsafe check
	if (bufferedSends.IsEmpty()==true)
		return;

	sendInProgressMutex.Lock();
	if (sendInProgress==true) {sendInProgressMutex.Unlock(); return;}
	else {sendInProgress=true;}
	sendInProgressMutex.Unlock();

	RNS2_SendParameters_NativeClient *sp;
	bufferedSendsMutex.Lock();
	if (bufferedSends.IsEmpty()==false)
		sp=bufferedSends.Pop();
	else
		sp=0;
	bufferedSendsMutex.Unlock();
	if (sp==0)
	{
		sendInProgressMutex.Lock();
		sendInProgress=false;
		sendInProgressMutex.Unlock();
		return; // Nothing to send after all
	}

	SendImmediate(sp);
	// sp remains in memory until the callback completes
	// DeallocSP(sp);
}
Esempio n. 2
0
void TCPClient::SendThread()
{
	UINT tick = timeGetTime();
	bool b10035;
	UINT hearbeat = HEARBEAT_ID;
	int timeout = m_InitData.Timeout >> 1;
	while (m_bConnected)
	{
		bool bSend = false;
		uint curTick = timeGetTime();
		while (m_SendList->HasItem())
		{
			NetCmd *pCmd = m_SendList->GetItemNoRemove();
			//Log("Client SendCmd, size:%d, type:%d", pCmd->GetCmdSize(), pCmd->GetCmdType());
			if (!SendImmediate(pCmd, pCmd->GetCmdSize(), b10035))
			{
				if (!b10035)
				{
					m_bConnected = false;
					break;
				}
			}
			else
			{
				tick = curTick;
				free(m_SendList->GetItem());
				bSend = true;
			}
		}
		if (bSend)
			tick = curTick;
		else if (int(curTick - tick) > timeout)
		{
			tick = curTick;
			if (!SendImmediate(&hearbeat, sizeof(hearbeat), b10035))
			{
				if (!b10035)
				{
					m_bConnected = false;
					break;
				}
			}
		}
		Sleep(m_InitData.SleepTime);
	}
	::InterlockedIncrement(&m_ExitCount);
}