Example #1
0
void TransportRegistry::put(Transport::shared_pointer const & transport)
{
    Lock guard(_mutex);
    //const string type = transport.getType();
    const int16 priority = transport->getPriority();
    const osiSockAddr* address = transport->getRemoteAddress();

    transportsMap_t::iterator transportsIter = _transports.find(address);
    prioritiesMapSharedPtr_t priorities;
    if(transportsIter == _transports.end())
    {
        priorities.reset(new prioritiesMap_t());
        _transports[address] = priorities;
        _transportCount++;
    }
    else
    {
        priorities = transportsIter->second;
        prioritiesMap_t::iterator prioritiesIter = priorities->find(priority);
        if(prioritiesIter == priorities->end()) //only increase transportCount if not replacing
        {
            _transportCount++;
        }
    }
    (*priorities)[priority] = transport;
}
Example #2
0
Transport::shared_pointer TransportRegistry::remove(Transport::shared_pointer const & transport)
{
    Lock guard(_mutex);
    const int16 priority = transport->getPriority();
    const osiSockAddr* address = transport->getRemoteAddress();
    Transport::shared_pointer retTransport;
    transportsMap_t::iterator transportsIter = _transports.find(address);
    if(transportsIter != _transports.end())
    {
        prioritiesMapSharedPtr_t priorities = transportsIter->second;
        prioritiesMap_t::iterator prioritiesIter = priorities->find(priority);
        if(prioritiesIter != priorities->end())
        {
            retTransport = prioritiesIter->second;
            priorities->erase(prioritiesIter);
            _transportCount--;
            if(priorities->size() == 0)
            {
                _transports.erase(transportsIter);
            }
        }
    }
    return retTransport;
}