From: Francis Dupont Date: Sat, 17 Mar 2018 00:32:24 +0000 (+0000) Subject: Updated cache insert X-Git-Tag: trac5458a_base~38^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d00dc35edbd590ca2d05aa021df9f6ac1a1abd5;p=thirdparty%2Fkea.git Updated cache insert --- diff --git a/src/lib/dhcpsrv/cache_host_data_source.h b/src/lib/dhcpsrv/cache_host_data_source.h index 9a4978a9aa..72a899eb76 100644 --- a/src/lib/dhcpsrv/cache_host_data_source.h +++ b/src/lib/dhcpsrv/cache_host_data_source.h @@ -25,16 +25,19 @@ public: /// Similar to @c add() but with a different purpose. /// /// @param host Pointer to the new @c Host object being inserted. - /// @param[in,out] overwrite -1 if accepting conflicts, 0 if removing - /// conflicting entries, set to the number of removed entries. - /// @return true when succeeded. - virtual bool insert(const ConstHostPtr& host, int& overwrite) = 0; + /// @param] overwrite false if doing nothing in case of conflicts + /// (and returning 1), true if removing conflicting entries + /// (and returning their number). + /// @return number of conflicts limited to one if overwrite is false. + virtual size_t insert(const ConstHostPtr& host, bool overwrite) = 0; /// @brief Remove a host from the cache. /// /// Does the same than @c del, @c del4 or @c del6 but with /// a more uniform interface and a different purpose. /// + /// @note A pointer to a copy does not remove the object. + /// /// @param host Pointer to the existing @c Host object being removed. /// @return true when found and removed. virtual bool remove(const HostPtr& host) = 0; diff --git a/src/lib/dhcpsrv/host_mgr.cc b/src/lib/dhcpsrv/host_mgr.cc index f53cf1b390..cfcd4eb6bd 100644 --- a/src/lib/dhcpsrv/host_mgr.cc +++ b/src/lib/dhcpsrv/host_mgr.cc @@ -467,9 +467,8 @@ HostMgr::cache(ConstHostPtr host) const { return; } // Replace any existing value. - int overwrite = 0; // Don't check the result as it does not matter? - cache_ptr_->insert(host, overwrite); + cache_ptr_->insert(host, true); } } @@ -486,9 +485,8 @@ HostMgr::cacheNegative(const SubnetID& ipv4_subnet_id, IOAddress::IPV4_ZERO_ADDRESS())); host->setNegative(true); // Don't replace any existing value. - int overwrite = -1; // nor matter if it fails. - cache_ptr_->insert(host, overwrite); + cache_ptr_->insert(host, false); } } diff --git a/src/lib/dhcpsrv/tests/host_cache_unittest.cc b/src/lib/dhcpsrv/tests/host_cache_unittest.cc index 7c972fdcd0..35008f6575 100644 --- a/src/lib/dhcpsrv/tests/host_cache_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_cache_unittest.cc @@ -43,11 +43,11 @@ public: } /// Insert - bool insert(const ConstHostPtr& host, int& overwrite) { - if (overwrite < 0) { - ++adds_; - } else { + size_t insert(const ConstHostPtr& host, bool overwrite) { + if (overwrite) { ++inserts_; + } else { + ++adds_; } HostPtr host_copy(new Host(*host)); store_.push_back(host_copy); @@ -706,7 +706,7 @@ public: } /// Insert throws - bool insert(const ConstHostPtr& host, int& overwrite) { + size_t insert(const ConstHostPtr& host, bool overwrite) { isc_throw(NotImplemented, "insert is not implemented: " << host->toText() << " with overwrite: " << overwrite);