Ejemplo n.º 1
0
THREAD_FUNC PacketHandler::PacketHandlerLoop( void* packetHandler )
{
	if ( NetworkControl::GetSingleton()->GetFlags() & NetworkControl::HANDLER_SYNC )
	{
		return 1;
	}

	PacketHandler* ph = (PacketHandler*) packetHandler;

	while ( true )
	{
		ph->m_PacketQueueSemaphore.Wait( INFINITE );

		if ( NetworkControl::GetSingleton()->m_StopRequestedEvent.Wait( 0 ) == true ||
			ph->m_ParentClient->m_StopEvent.Wait( 0 ) == true )
		{
			break;
		}

		ph->m_PacketAdditionMutex.Lock();

		// Get a packet from the queue.
		Packet* handlePacket = ph->m_PacketQueue.front();
		ph->m_PacketQueue.pop();

		ph->m_PacketAdditionMutex.Unlock();

		// Handle the packet if its operation code is recognized
		OpCodeHandler::GetSingleton()->CallOpCodeFunction( handlePacket->GetOpCode(), handlePacket );

		delete handlePacket;
	}

	return 1;
}
Ejemplo n.º 2
0
unsigned int PacketHandler::HandlePackets( void )
{
	if ( !( NetworkControl::GetSingleton()->GetFlags() & NetworkControl::HANDLER_SYNC ) )
	{
		return 0;
	}

	unsigned int amount = 0;

	m_PacketAdditionMutex.Lock();

	while ( m_PacketQueue.size() > 0 )
	{
		// Get a packet from the queue.
		Packet* handlePacket = m_PacketQueue.front();
		m_PacketQueue.pop();

		// Handle the packet if its operation code is recognized
		OpCodeHandler::GetSingleton()->CallOpCodeFunction( handlePacket->GetOpCode(), handlePacket );

		delete handlePacket;
		amount++;
	}

	m_PacketAdditionMutex.Unlock();

	return amount;
}