]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
Updated cache insert
authorFrancis Dupont <fdupont@isc.org>
Sat, 17 Mar 2018 00:32:24 +0000 (00:32 +0000)
committerFrancis Dupont <fdupont@isc.org>
Sat, 17 Mar 2018 00:32:24 +0000 (00:32 +0000)
src/lib/dhcpsrv/cache_host_data_source.h
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/tests/host_cache_unittest.cc

index 9a4978a9aa41e72b5acf998a61f2d0246c179e87..72a899eb7677f9439f664bd5b57974786c931961 100644 (file)
@@ -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;
index f53cf1b39096e122e6d5ee480db38b29309ab340..cfcd4eb6bd69f8293ad6c8ff9883c99c450198f7 100644 (file)
@@ -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);
     }
 }
 
index 7c972fdcd0a88503d6e16bbdf25a5561a8dbad23..35008f657507ac3fd0a3af03887cd84452e714c2 100644 (file)
@@ -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);