Transport Registry map uses osiSockAddr as key
This commit is contained in:
@@ -28,15 +28,13 @@ void TransportRegistry::put(Transport* transport)
|
||||
//const string type = transport.getType();
|
||||
const int16 priority = transport->getPriority();
|
||||
const osiSockAddr* address = transport->getRemoteAddress();
|
||||
const int32 intAddress = ipv4AddressToInt(*address);
|
||||
|
||||
|
||||
_transportsIter = _transports.find(intAddress);
|
||||
_transportsIter = _transports.find(address);
|
||||
prioritiesMap_t* priorities;
|
||||
if(_transportsIter == _transports.end())
|
||||
{
|
||||
priorities = new prioritiesMap_t();
|
||||
_transports[intAddress] = priorities;
|
||||
_transports[address] = priorities;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -55,8 +53,7 @@ Transport* TransportRegistry::get(const string type, const osiSockAddr* address,
|
||||
}
|
||||
|
||||
Lock guard(&_mutex);
|
||||
const int32 intAddress = ipv4AddressToInt(*address);
|
||||
_transportsIter = _transports.find(intAddress);
|
||||
_transportsIter = _transports.find(address);
|
||||
if(_transportsIter != _transports.end())
|
||||
{
|
||||
prioritiesMap_t* priorities = _transportsIter->second;
|
||||
@@ -78,8 +75,7 @@ Transport** TransportRegistry::get(const string type, const osiSockAddr* address
|
||||
}
|
||||
|
||||
Lock guard(&_mutex);
|
||||
const int32 intAddress = ipv4AddressToInt(*address);
|
||||
_transportsIter = _transports.find(intAddress);
|
||||
_transportsIter = _transports.find(address);
|
||||
if(_transportsIter != _transports.end())
|
||||
{
|
||||
prioritiesMap_t* priorities = _transportsIter->second;
|
||||
@@ -106,9 +102,8 @@ Transport* TransportRegistry::remove(Transport* transport)
|
||||
Lock guard(&_mutex);
|
||||
const int16 priority = transport->getPriority();
|
||||
const osiSockAddr* address = transport->getRemoteAddress();
|
||||
const int32 intAddress = ipv4AddressToInt(*address);
|
||||
Transport* retTransport = NULL;
|
||||
_transportsIter = _transports.find(intAddress);
|
||||
_transportsIter = _transports.find(address);
|
||||
if(_transportsIter != _transports.end())
|
||||
{
|
||||
prioritiesMap_t* priorities = _transportsIter->second;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef TRANSPORTREGISTRY_H
|
||||
#define TRANSPORTREGISTRY_H
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
@@ -24,9 +23,20 @@ using namespace std;
|
||||
|
||||
namespace epics { namespace pvAccess {
|
||||
|
||||
//TODO if unordered map is used instead of map we can use sockAddrAreIdentical routine from osiSock.h
|
||||
struct comp_osiSockAddr
|
||||
{
|
||||
bool operator()(osiSockAddr const *a, osiSockAddr const *b)
|
||||
{
|
||||
if (a->sa.sa_family < b->sa.sa_family) return true;
|
||||
if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr < b->ia.sin_addr.s_addr )) return true;
|
||||
if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr == b->ia.sin_addr.s_addr ) && ( a->ia.sin_port < b->ia.sin_port )) return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<const int16,Transport*> prioritiesMap_t;
|
||||
typedef std::map<const int32,prioritiesMap_t*> transportsMap_t;
|
||||
typedef std::map<const osiSockAddr*,prioritiesMap_t*,comp_osiSockAddr> transportsMap_t;
|
||||
typedef std::vector<Transport*> allTransports_t;
|
||||
|
||||
class TransportRegistry {
|
||||
|
||||
@@ -68,6 +68,8 @@ int main(int argc, char *argv[])
|
||||
osiSockAddr* addr = new osiSockAddr;
|
||||
addrArray[i] = addr;
|
||||
addr->ia.sin_addr.s_addr = i;
|
||||
addr->ia.sin_port = i;
|
||||
addr->ia.sin_family = AF_INET;
|
||||
|
||||
//priority
|
||||
for(int16 j = 0; j < priority_max; j++)
|
||||
|
||||
Reference in New Issue
Block a user