Commit 0503f4a6 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac575] Move the setting up of addresses

Taken out from resolver and put into the server_common library.
parent 71c4e3cb
......@@ -573,48 +573,9 @@ Resolver::getRootAddresses() const {
return (impl_->upstream_root_);
}
namespace {
void
setAddresses(DNSService *service, const vector<AddressPair>& addresses) {
service->clearServers();
BOOST_FOREACH(const AddressPair &address, addresses) {
service->addServer(address.second, address.first);
}
}
}
void
Resolver::setListenAddresses(const vector<AddressPair>& addresses) {
try {
dlog("Setting listen addresses:");
BOOST_FOREACH(const AddressPair& addr, addresses) {
dlog(" " + addr.first + ":" +
boost::lexical_cast<string>(addr.second));
}
setAddresses(dnss_, addresses);
impl_->listen_ = addresses;
}
catch (const exception& e) {
/*
* We couldn't set it. So return it back. If that fails as well,
* we have a problem.
*
* If that fails, bad luck, but we are useless anyway, so just die
* and let boss start us again.
*/
dlog(string("Unable to set new address: ") + e.what(), true);
try {
setAddresses(dnss_, impl_->listen_);
}
catch (const exception& e2) {
dlog("Unable to recover from error;", true);
dlog(string("Rollback failed with: ") + e2.what(), true);
abort();
}
throw e; // Let it fly a little bit further
}
installListenAddresses(addresses, impl_->listen_, *dnss_);
}
void
......
......@@ -21,5 +21,6 @@ libserver_common_la_SOURCES = portconfig.h portconfig.cc
libserver_common_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/cc/libcc.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/log/liblog.la
CLEANFILES = *.gcno *.gcda
......@@ -15,10 +15,16 @@
#include "portconfig.h"
#include <asiolink/io_address.h>
#include <asiolink/dns_service.h>
#include <log/dummylog.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace isc::data;
using namespace asiolink;
using isc::log::dlog;
namespace isc {
namespace server_common {
......@@ -61,8 +67,52 @@ parseAddresses(isc::data::ConstElementPtr addresses,
return (result);
}
namespace {
void
setAddresses(DNSService& service, const AddressList& addresses) {
service.clearServers();
BOOST_FOREACH(const AddressPair &address, addresses) {
service.addServer(address.second, address.first);
}
}
}
void
installListenAddresses(const AddressList&, AddressList&, asiolink::DNSService&) {}
installListenAddresses(const AddressList& newAddresses,
AddressList& addressStore,
asiolink::DNSService& service)
{
try {
dlog("Setting listen addresses:");
BOOST_FOREACH(const AddressPair& addr, newAddresses) {
dlog(" " + addr.first + ":" +
boost::lexical_cast<string>(addr.second));
}
setAddresses(service, newAddresses);
addressStore = newAddresses;
}
catch (const exception& e) {
/*
* We couldn't set it. So return it back. If that fails as well,
* we have a problem.
*
* If that fails, bad luck, but we are useless anyway, so just die
* and let boss start us again.
*/
dlog(string("Unable to set new address: ") + e.what(), true);
try {
setAddresses(service, addressStore);
}
catch (const exception& e2) {
dlog("Unable to recover from error;", true);
dlog(string("Rollback failed with: ") + e2.what(), true);
abort();
}
throw e; // Let it fly a little bit further
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment