namespace isc {
namespace dhcp {
-/// @brief Client race avoidance RAII handler.
-class ClientHandler : public boost::noncopyable {
-public:
+/// @brief Define the type of packet processing continuation.
+typedef std::function<void()> Continuation;
- /// @brief Define the type of packet processing continuation.
- typedef std::function<void()> Continuation;
+/// @brief Define the type of shared pointers to continuations.
+typedef boost::shared_ptr<Continuation> ContinuationPtr;
- /// @brief Define the type of shared pointers to continuations.
- typedef boost::shared_ptr<Continuation> ContinuationPtr;
+/// @brief Continuation factory.
+///
+/// @param cont Continuation rvalue.
+inline ContinuationPtr makeContinuation(Continuation&& cont) {
+ return (boost::make_shared<Continuation>(cont));
+}
- /// @brief Continuation factory.
- ///
- /// @param cont Continuation rvalue.
- static ContinuationPtr makeContinuation(Continuation&& cont) {
- return (boost::make_shared<Continuation>(cont));
- }
+/// @brief Client race avoidance RAII handler.
+class ClientHandler : public boost::noncopyable {
+public:
/// @brief Constructor.
ClientHandler();
return;
}
- // Create a client race avoidance RAII handler.
- ClientHandler client_handler;
-
- // Check for lease modifier queries from the same client being processed.
- if (MultiThreadingMgr::instance().getMode() &&
- ((query->getType() == DHCPDISCOVER) ||
- (query->getType() == DHCPREQUEST) ||
- (query->getType() == DHCPRELEASE) ||
- (query->getType() == DHCPDECLINE))) {
- if (client_handler.tryLock(query)) {
- return;
- }
- }
-
processDhcp4Query(query, rsp, allow_packet_park);
}
void
Dhcpv4Srv::processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp,
bool allow_packet_park) {
+ // Create a client race avoidance RAII handler.
+ ClientHandler client_handler;
+
+ // Check for lease modifier queries from the same client being processed.
+ if (MultiThreadingMgr::instance().getMode() &&
+ ((query->getType() == DHCPDISCOVER) ||
+ (query->getType() == DHCPREQUEST) ||
+ (query->getType() == DHCPRELEASE) ||
+ (query->getType() == DHCPDECLINE))) {
+ ContinuationPtr cont =
+ makeContinuation(std::bind(&Dhcpv4Srv::processDhcp4QueryAndSendResponse,
+ this, query, rsp, allow_packet_park));
+ if (client_handler.tryLock(query, cont)) {
+ return;
+ }
+ }
+
AllocEngine::ClientContext4Ptr ctx;
try {
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the discover.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the discover.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the discover.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler3;
// Create a continuation.
- ClientHandler::ContinuationPtr cont3 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
+ ContinuationPtr cont3 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
// Try to lock it with a release.
EXPECT_NO_THROW(duplicate = client_handler3.tryLock(rel, cont3));
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the discover.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler3;
// Create a continuation.
- ClientHandler::ContinuationPtr cont3 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
+ ContinuationPtr cont3 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
// Try to lock it with a release.
EXPECT_NO_THROW(duplicate = client_handler3.tryLock(rel, cont3));
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the discover.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler3;
// Create a continuation.
- ClientHandler::ContinuationPtr cont3 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
+ ContinuationPtr cont3 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
// Try to lock it with a release.
EXPECT_NO_THROW(duplicate = client_handler3.tryLock(rel, cont3));
namespace isc {
namespace dhcp {
-/// @brief Client race avoidance RAII handler.
-class ClientHandler : public boost::noncopyable {
-public:
+/// @brief Define the type of packet processing continuation.
+typedef std::function<void()> Continuation;
- /// @brief Define the type of packet processing continuation.
- typedef std::function<void()> Continuation;
+/// @brief Define the type of shared pointers to continuations.
+typedef boost::shared_ptr<Continuation> ContinuationPtr;
- /// @brief Define the type of shared pointers to continuations.
- typedef boost::shared_ptr<Continuation> ContinuationPtr;
+/// @brief Continuation factory.
+///
+/// @param cont Continuation rvalue.
+inline ContinuationPtr makeContinuation(Continuation&& cont) {
+ return (boost::make_shared<Continuation>(cont));
+}
- /// @brief Continuation factory.
- ///
- /// @param cont Continuation rvalue.
- static ContinuationPtr makeContinuation(Continuation&& cont) {
- return (boost::make_shared<Continuation>(cont));
- }
+/// @brief Client race avoidance RAII handler.
+class ClientHandler : public boost::noncopyable {
+public:
/// @brief Constructor.
ClientHandler();
(query->getType() == DHCPV6_REBIND) ||
(query->getType() == DHCPV6_RELEASE) ||
(query->getType() == DHCPV6_DECLINE))) {
- drop = client_handler.tryLock(query);
+ ContinuationPtr cont =
+ makeContinuation(std::bind(&Dhcpv6Srv::processDhcp6QueryAndSendResponse,
+ this, query, rsp));
+ drop = client_handler.tryLock(query, cont);
}
// Stop here if ClientHandler tryLock decided the packet is a duplicate.
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the solicit.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler;
// Create a continuation.
- ClientHandler::ContinuationPtr cont1 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
+ ContinuationPtr cont1 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled1, this));
// Try to lock it with the solicit.
bool duplicate = false;
ClientHandler client_handler2;
// Create a continuation.
- ClientHandler::ContinuationPtr cont2 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
+ ContinuationPtr cont2 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled2, this));
// Try to lock it with a request.
EXPECT_NO_THROW(duplicate = client_handler2.tryLock(req, cont2));
ClientHandler client_handler3;
// Create a continuation.
- ClientHandler::ContinuationPtr cont3 =
- ClientHandler::makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
+ ContinuationPtr cont3 =
+ makeContinuation(std::bind(&ClientHandleTest::setCalled3, this));
// Try to lock it with a renew.
EXPECT_NO_THROW(duplicate = client_handler3.tryLock(ren, cont3));