void addServerToPool(pools_t& pools, const string& poolName, std::shared_ptr<DownstreamState> server);
void removeServerFromPool(pools_t& pools, const string& poolName, std::shared_ptr<DownstreamState> server);
-const std::shared_ptr<ServerPolicy::NumberedServerVector> getDownstreamCandidates(const map<std::string,std::shared_ptr<ServerPool>>& pools, const std::string& poolName);
+const std::shared_ptr<const ServerPolicy::NumberedServerVector> getDownstreamCandidates(const map<std::string,std::shared_ptr<ServerPool>>& pools, const std::string& poolName);
std::shared_ptr<DownstreamState> firstAvailable(const ServerPolicy::NumberedServerVector& servers, const DNSQuestion* dq);
struct ServerPool
{
- ServerPool(): d_servers(std::make_shared<ServerPolicy::NumberedServerVector>())
+ ServerPool(): d_servers(std::make_shared<const ServerPolicy::NumberedServerVector>())
{
}
size_t poolLoad();
size_t countServers(bool upOnly);
- const std::shared_ptr<ServerPolicy::NumberedServerVector> getServers();
+ const std::shared_ptr<const ServerPolicy::NumberedServerVector> getServers();
void addServer(shared_ptr<DownstreamState>& server);
void removeServer(shared_ptr<DownstreamState>& server);
private:
- SharedLockGuarded<std::shared_ptr<ServerPolicy::NumberedServerVector>> d_servers;
+ SharedLockGuarded<std::shared_ptr<const ServerPolicy::NumberedServerVector>> d_servers;
bool d_useECS{false};
};
size_t ServerPool::countServers(bool upOnly)
{
- std::shared_ptr<ServerPolicy::NumberedServerVector> servers = nullptr;
+ std::shared_ptr<const ServerPolicy::NumberedServerVector> servers = nullptr;
{
auto lock = d_servers.read_lock();
servers = *lock;
size_t ServerPool::poolLoad()
{
- std::shared_ptr<ServerPolicy::NumberedServerVector> servers = nullptr;
+ std::shared_ptr<const ServerPolicy::NumberedServerVector> servers = nullptr;
{
auto lock = d_servers.read_lock();
servers = *lock;
return load;
}
-const std::shared_ptr<ServerPolicy::NumberedServerVector> ServerPool::getServers()
+const std::shared_ptr<const ServerPolicy::NumberedServerVector> ServerPool::getServers()
{
- std::shared_ptr<ServerPolicy::NumberedServerVector> result;
+ std::shared_ptr<const ServerPolicy::NumberedServerVector> result;
{
result = *(d_servers.read_lock());
}
/* we can't update the content of the shared pointer directly even when holding the lock,
as other threads might hold a copy. We can however update the pointer as long as we hold the lock. */
unsigned int count = static_cast<unsigned int>((*servers)->size());
- auto newServers = std::make_shared<ServerPolicy::NumberedServerVector>(*(*servers));
- newServers->emplace_back(++count, server);
+ auto newServers = ServerPolicy::NumberedServerVector(*(*servers));
+ newServers.emplace_back(++count, server);
/* we need to reorder based on the server 'order' */
- std::stable_sort(newServers->begin(), newServers->end(), [](const std::pair<unsigned int,std::shared_ptr<DownstreamState> >& a, const std::pair<unsigned int,std::shared_ptr<DownstreamState> >& b) {
+ std::stable_sort(newServers.begin(), newServers.end(), [](const std::pair<unsigned int,std::shared_ptr<DownstreamState> >& a, const std::pair<unsigned int,std::shared_ptr<DownstreamState> >& b) {
return a.second->d_config.order < b.second->d_config.order;
});
/* and now we need to renumber for Lua (custom policies) */
size_t idx = 1;
- for (auto& serv : *newServers) {
+ for (auto& serv : newServers) {
serv.first = idx++;
}
- *servers = std::move(newServers);
+ *servers = std::make_shared<const ServerPolicy::NumberedServerVector>(std::move(newServers));
}
void ServerPool::removeServer(shared_ptr<DownstreamState>& server)