Commit 148c5bbf authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2850] Make getHeader() return the current address of header

It could have been relocated since its construction.
parent 4542e896
......@@ -36,8 +36,7 @@ const char* const ZONE_TABLE_HEADER_NAME = "zone_table_header";
ZoneTableSegmentMapped::ZoneTableSegmentMapped(const RRClass& rrclass) :
ZoneTableSegment(rrclass),
rrclass_(rrclass),
header_(NULL)
rrclass_(rrclass)
{
}
......@@ -121,7 +120,6 @@ ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment,
return (false);
} else {
assert(result.second);
header_ = static_cast<ZoneTableHeader*>(result.second);
}
} else {
// First allocate a ZONE_TABLE_HEADER_NAME, so that we can set
......@@ -150,7 +148,6 @@ ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment,
error_msg = "Segment grew unexpectedly in setNamedAddress()";
return (false);
}
header_ = new_header;
}
return (true);
......@@ -217,7 +214,6 @@ ZoneTableSegmentMapped::openReadOnly(const std::string& filename) {
result = segment->getNamedAddress(ZONE_TABLE_HEADER_NAME);
if (result.first) {
assert(result.second);
header_ = static_cast<ZoneTableHeader*>(result.second);
} else {
const std::string error_msg =
"There is no previously saved ZoneTableHeader in a "
......@@ -309,27 +305,37 @@ void
ZoneTableSegmentMapped::clear() {
if (mem_sgmt_) {
sync();
header_ = NULL;
mem_sgmt_.reset();
}
}
ZoneTableHeader&
ZoneTableSegmentMapped::getHeader() {
template<typename T>
T*
ZoneTableSegmentMapped::getHeaderHelper() const {
if (!mem_sgmt_) {
isc_throw(isc::InvalidOperation,
"getHeader() called without calling reset() first");
}
return (*header_);
const MemorySegment::NamedAddressResult result =
mem_sgmt_->getNamedAddress(ZONE_TABLE_HEADER_NAME);
if (!result.first) {
isc_throw(isc::Unexpected,
"Unable to look up the address of the table header in "
"getHeader()");
}
return (static_cast<T*>(result.second));
}
ZoneTableHeader&
ZoneTableSegmentMapped::getHeader() {
return (*getHeaderHelper<ZoneTableHeader>());
}
const ZoneTableHeader&
ZoneTableSegmentMapped::getHeader() const {
if (!mem_sgmt_) {
isc_throw(isc::InvalidOperation,
"getHeader() called without calling reset() first");
}
return (*header_);
return (*getHeaderHelper<const ZoneTableHeader>());
}
MemorySegment&
......
......@@ -118,6 +118,8 @@ private:
void openReadWrite(const std::string& filename, bool create);
void openReadOnly(const std::string& filename);
template<typename T> T* getHeaderHelper() const;
private:
isc::dns::RRClass rrclass_;
MemorySegmentOpenMode current_mode_;
......@@ -125,7 +127,6 @@ private:
// Internally holds a MemorySegmentMapped. This is NULL on
// construction, and is set by the \c reset() method.
boost::scoped_ptr<isc::util::MemorySegmentMapped> mem_sgmt_;
ZoneTableHeader* header_;
};
} // namespace memory
......
Markdown is supported
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