Example #1
0
Message* LocalTransport::CreateMessage(uint32_t protocol, uint32_t code)
{
    Message* message = 0;
    std::map<uint32_t, std::list<Message*> >::iterator it;
    it = mMessagePool.find(protocol);

    if (it != mMessagePool.end())
    {
        if (it->second.size())
        {
            // free message in pool, use that
            message = it->second.front();
            it->second.pop_front();
        }
    }
    else
    {
        // initialize a list
        mMessagePool[protocol].clear();
    }
    if(message == 0)
    {
        // no more messages, create a new one
        message = mHandlers.Create(protocol, code);
        message->AddToPool(*this);
    }

    message->AddRef();
    return message;
}