Kea 2.7.6
isc::hooks::ScopedCalloutHandleState Class Reference

Wrapper class around callout handle which automatically resets handle's state. More...

#include <callout_handle.h>

Public Member Functions

 ScopedCalloutHandleState (const CalloutHandlePtr &callout_handle)
 Constructor.
 
 ~ScopedCalloutHandleState ()
 Destructor.
 

Public Attributes

std::function< void()> on_completion_
 Continuation callback.
 

Detailed Description

Wrapper class around callout handle which automatically resets handle's state.

The Kea servers often require to associate processed packets with CalloutHandle instances. This is to facilitate the case when the hooks library passes information between the callouts using the 'context' stored in the callout handle. The callouts invoked throughout the packet lifetime have access to the context information for the given packet.

The association between the packets and the callout handles is achieved by giving the ownership of the CalloutHandle objects to the Pkt objects. When the Pkt object goes out of scope, it should also release the pointer to the owned CalloutHandle object. However, this causes a risk of circular dependency between the shared pointer to the Pkt object and the shared pointer to the CalloutHandle it owns, because the pointer to the packet is often set as an argument of the callout handle prior to invoking a callout.

In order to break the circular dependency, the arguments of the callout handle must be deleted as soon as they are not needed anymore. This class is a wrapper around the callout handle object, which resets its state during construction and destruction. All Kea hook points must use this class within the scope where the HooksManager::callCallouts is invoked to reset the state of the callout handle. The state is reset when this object goes out of scope.

Currently, the following operations are performed during the reset:

  • all arguments of the callout handle are deleted,
  • the next step status is set to CalloutHandle::NEXT_STEP CONTINUE

This class must never be modified to also delete the context information from the callout handle. The context is intended to be used to share stateful data across callouts and hook points and its contents must exist for the duration of the packet lifecycle. Otherwise, we could simply re-create the callout handle for each hook point and we wouldn't need this RAII class.

Definition at line 510 of file callout_handle.h.

Constructor & Destructor Documentation

◆ ScopedCalloutHandleState()

isc::hooks::ScopedCalloutHandleState::ScopedCalloutHandleState ( const CalloutHandlePtr & callout_handle)
explicit

Constructor.

Resets state of the callout handle.

Parameters
callout_handlereference to the pointer to the callout handle which state should be reset.
Exceptions
isc::BadValueif the callout handle is null.

Definition at line 138 of file callout_handle.cc.

References isc_throw.

◆ ~ScopedCalloutHandleState()

isc::hooks::ScopedCalloutHandleState::~ScopedCalloutHandleState ( )

Destructor.

Resets state of the callout handle.

Definition at line 148 of file callout_handle.cc.

References on_completion_.

Member Data Documentation

◆ on_completion_

std::function<void()> isc::hooks::ScopedCalloutHandleState::on_completion_

Continuation callback.

Definition at line 528 of file callout_handle.h.

Referenced by ~ScopedCalloutHandleState().


The documentation for this class was generated from the following files: