Minor clean-up and typos.
src/hooks/dhcp/high_availability/ha_impl.cc
HAImpl::leases4Committed()
HAImpl::leases6Committed() - added try-catch to ensure
we call dereference on error
try {
stopD2();
- } catch(const std::exception& ex) {
+ } catch (const std::exception& ex) {
// Highly unlikely, but lets Report it but go on
LOG_ERROR(dhcp4_logger, DHCP4_SRV_D2STOP_ERROR).arg(ex.what());
}
try {
Dhcp4to6Ipc::instance().close();
- } catch(const std::exception& ex) {
+ } catch (const std::exception& ex) {
// Highly unlikely, but lets Report it but go on
LOG_ERROR(dhcp4_logger, DHCP4_SRV_DHCP4O6_ERROR).arg(ex.what());
}
// Call all installed callouts
HooksManager::callCallouts(Hooks.hook_index_leases4_committed_,
*callout_handle);
- } catch(...) {
+ } catch (...) {
// Make sure we don't orphan a parked packet.
if (allow_packet_park) {
HooksManager::drop("leases4_committed", query);
try {
stopD2();
- } catch(const std::exception& ex) {
+ } catch (const std::exception& ex) {
// Highly unlikely, but lets Report it but go on
LOG_ERROR(dhcp6_logger, DHCP6_SRV_D2STOP_ERROR).arg(ex.what());
}
try {
Dhcp6to4Ipc::instance().close();
- } catch(const std::exception& ex) {
+ } catch (const std::exception& ex) {
// Highly unlikely, but lets Report it but go on
// LOG_ERROR(dhcp6_logger, DHCP6_SRV_DHCP4O6_ERROR).arg(ex.what());
}
// Call all installed callouts
HooksManager::callCallouts(Hooks.hook_index_leases6_committed_,
*callout_handle);
- } catch(...) {
+ } catch (...) {
// Make sure we don't orphan a parked packet.
HooksManager::drop("leases4_committed", query);
throw;
// e.g. when this server is in the partner-down state and there are no backup
// servers. In those cases we simply return without parking the DHCP query.
// The response will be sent to the client immediately.
- if (service_->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
- // Dereference the parked packet. This releases our stake in it.
+ try {
+ if (service_->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
+ // Dereference the parked packet. This releases our stake in it.
+ parking_lot->dereference(query4);
+ return;
+ }
+ } catch (...) {
+ // Make sure we dereference.
parking_lot->dereference(query4);
- return;
+ throw;
}
// The callout returns this status code to indicate to the server that it
- // should leave the packet parked. It will be unparked until each hook
+ // should leave the packet parked. It will be parked until each hook
// library with a reference, unparks the packet.
callout_handle.setStatus(CalloutHandle::NEXT_STEP_PARK);
}
// e.g. when this server is in the partner-down state and there are no backup
// servers. In those cases we simply return without parking the DHCP query.
// The response will be sent to the client immediately.
- if (service_->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
- // Dereference the parked packet. This releases our stake in it.
+ try {
+ if (service_->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
+ // Dereference the parked packet. This releases our stake in it.
+ parking_lot->dereference(query6);
+ return;
+ }
+ } catch (...) {
+ // Make sure we dereference.
parking_lot->dereference(query6);
- return;
+ throw;
}
// The callout returns this status code to indicate to the server that it
ScopedCalloutHandleState handle_state(handle);
handle->setArgument("query4", query);
- // Park the packtet proactively as the server normally would.
+ // Park the packet proactively as the server normally would.
HooksManager::park("leases4_committed", query, []{});
// Invoke the callouts.
ScopedCalloutHandleState handle_state(handle);
handle->setArgument("query6", query);
- // Park the packtet proactively as the server normally would.
+ // Park the packet proactively as the server normally would.
HooksManager::park("leases6_committed", query, []{});
// Invoke the callouts.
HooksManager::park("leases4_committed", query4, []{});
// Run the callout again.
- ASSERT_NO_THROW_LOG(ha_impl.leases4Committed(*callout_handle));
+ ASSERT_NO_THROW(ha_impl.leases4Committed(*callout_handle));
// This time the lease update should be generated and the status should
// be set to "park".
// Add the object to the parking lot. At this point refcount = 0.
ParkingInfo pinfo(parked_object, unpark_callback);
parking_[makeKey(parked_object)] = pinfo;
- return;
}
/// @brief Increases reference counter for the parked object.
}
// Decrement and return the reference count.
- return (--it->second.refcount_);
+ return (--it->second.refcount_);
}
/// @brief Signals that the object should be unparked.
std::string makeKey(T parked_object) {
std::stringstream ss;
ss << boost::any_cast<T>(parked_object);
- return(ss.str());
+ return (ss.str());
}
/// @brief Search for the information about the parked object.
/// if no such object found.
template<typename T>
ParkingInfoListIterator find(T parked_object) {
- return(parking_.find(makeKey(parked_object)));
+ return (parking_.find(makeKey(parked_object)));
}
/// @brief The mutex to protect parking lot internal state.
StringPtr parked_object(new std::string("foo"));
+ // Unparking should return false if the object isn't parked.
+ EXPECT_FALSE(parking_lot->unpark(parked_object));
+
// This flag will indicate if the callback has been called.
bool unparked = false;
+
ASSERT_NO_THROW(parking_lot->park(parked_object, [&unparked] {
unparked = true;
}));
EXPECT_TRUE(weak_parked_object.expired());
}
-// Verify that an object can be derefernced.
+// Verify that an object can be dereferenced.
TEST(ParkingLotsTest, dereference) {
ParkingLotPtr parking_lot = boost::make_shared<ParkingLot>();
ParkingLotHandlePtr parking_lot_handle =
ASSERT_EQ(0, ref_count);
EXPECT_FALSE(unparked);
- // Try to dereference the object. It should -1.
+ // Try to dereference the object. It should decrement to -1
// but not unpark the packet or invoke the callback.
ASSERT_NO_THROW(ref_count = parking_lot_handle->dereference(parked_object));
EXPECT_EQ(-1, ref_count);