void SocketWriteThread::_send(Session* session)
{
	Packet*             packet;
	
	// Send any outgoing reliable packets - retain those
	while (session->getOutgoingReliablePacket(packet))    {
		//dont destroy reliables - they get queued until acked or resend
        _sendPacket(packet, session);
    }

    // Send any outgoing unreliable packets	
    while (session->getOutgoingUnreliablePacket(packet))    {
        _sendPacket(packet, session);
        session->DestroyPacket(packet);
    }

	// If the session is still in a connected state, Put us back in the queue.
	// otherwise inform the service that we need destroying
	if (session->getStatus() != SSTAT_Disconnected)	{
		mSessionQueue.push(session);
	}	else	{
		session->setStatus(SSTAT_Destroy);
		mService->AddSessionToProcessQueue(session);
	}

}
void TcpClientModule_Impl::sendPacket(UInt16 moduleId, google::protobuf::MessageLite* pbBody)
{
	m_TTPBHeader.clear();
	m_TTPBHeader.setModuleId(moduleId);

	_sendPacket(pbBody);
}
void TcpClientModule_Impl::sendPacket(UInt16 moduleId, UInt16 cmdId, UInt16 seq, google::protobuf::MessageLite* pbBody)
{
	m_TTPBHeader.clear();
	m_TTPBHeader.setModuleId(moduleId);
	m_TTPBHeader.setCommandId(cmdId);
	m_TTPBHeader.setSeqNumber(seq);

	_sendPacket(pbBody);
}
Exemple #4
0
void *FricXactor::Send(void *args)
{
  for(;;)
    {
      boost::shared_ptr<FricData> sendData = inChan.get();

      ExecuteCallbacks(SendCB, sendData.get());
      _sendPacket(*(sendData->ptype), *(sendData->port), *(sendData->addr), *(sendData->data));
    }

  return 0;
}
	void ServerBase::_sendMessage( ServerPlayer* player, const std::string& message, int channel )
	{
		//key not set yet
		if(player->getCryptoKey().length() == 0)
		{
			setBuffer(m_cryptBuffer,message.c_str(),message.length());
		}
		else //use the key to encrypt packet
		{
			m_cryptBuffer.resize(message.length() + 1,0);
			m_cipher.encrypt(&m_cryptBuffer[0],
				message.c_str(),message.length() + 1,player->getCryptoKey());
		}

		_sendPacket(player,&m_cryptBuffer[0],m_cryptBuffer.size(),channel);

	}
//======================================================================================================================
void SocketWriteThread::run()
{
    Session*            session;
    Packet*             packet;

    // Call our internal _startup method
    _startup();

    uint32 packets = 50;
    if(mServerService)
        packets = 1000;


    // Main loop
    while(!mExit)
    {

        uint32 sessionCount = mSessionQueue.size();

        for(uint32 i = 0; i < sessionCount; i++)
        {
            uint32 packetCount = 0;
            session = mSessionQueue.pop();

            if(!session)
                continue;

            // Process our session
            session->ProcessWriteThread();

            // Send any outgoing reliable packets
            //uint32 rcount = 0;

            while (session->getOutgoingReliablePacketCount())
            {
                packetCount++;
                if(packetCount > packets)
                    break;

                LOG(INFO) << "Reliable packet sent";
                packet = session->getOutgoingReliablePacket();
                _sendPacket(packet, session);
            }


            packetCount = 0;

            // Send any outgoing unreliable packets
            //uint32 ucount = 0;
            while (session->getOutgoingUnreliablePacketCount())
            {
                LOG(INFO) << "Unreliable packet sent";
                packet = session->getOutgoingUnreliablePacket();
                _sendPacket(packet, session);
                session->DestroyPacket(packet);
            }


            // If the session is still in a connected state, Put us back in the queue.
            if (session->getStatus() != SSTAT_Disconnected)
            {
                mSessionQueue.push(session);
            }
            else
            {
                DLOG(INFO) << "Socket Write Thread: Destroy Session";

                session->setStatus(SSTAT_Destroy);
                mService->AddSessionToProcessQueue(session);
            }
        }


        boost::this_thread::sleep(boost::posix_time::milliseconds(1));
    }

    // Shutdown internally
    _shutdown();
}